diff options
Diffstat (limited to 'common/src/com')
-rw-r--r-- | common/src/com/android/AndroidConstants.java | 50 | ||||
-rw-r--r-- | common/src/com/android/io/FileWrapper.java | 151 | ||||
-rw-r--r-- | common/src/com/android/io/FolderWrapper.java | 154 | ||||
-rw-r--r-- | common/src/com/android/io/IAbstractFile.java | 58 | ||||
-rw-r--r-- | common/src/com/android/io/IAbstractFolder.java | 77 | ||||
-rw-r--r-- | common/src/com/android/io/IAbstractResource.java | 45 | ||||
-rw-r--r-- | common/src/com/android/io/StreamException.java | 28 | ||||
-rw-r--r-- | common/src/com/android/resources/FolderTypeRelationship.java | 164 | ||||
-rw-r--r-- | common/src/com/android/resources/ResourceFolderType.java | 78 | ||||
-rw-r--r-- | common/src/com/android/resources/ResourceType.java | 4 |
10 files changed, 807 insertions, 2 deletions
diff --git a/common/src/com/android/AndroidConstants.java b/common/src/com/android/AndroidConstants.java new file mode 100644 index 0000000..dfe137a --- /dev/null +++ b/common/src/com/android/AndroidConstants.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2011 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; + +/** + * Generic Android Constants. + */ +public class AndroidConstants { + + /** Default anim resource folder name, i.e. "anim" */ + public final static String FD_RES_ANIM = "anim"; //$NON-NLS-1$ + /** Default animator resource folder name, i.e. "animator" */ + public final static String FD_RES_ANIMATOR = "animator"; //$NON-NLS-1$ + /** Default color resource folder name, i.e. "color" */ + public final static String FD_RES_COLOR = "color"; //$NON-NLS-1$ + /** Default drawable resource folder name, i.e. "drawable" */ + public final static String FD_RES_DRAWABLE = "drawable"; //$NON-NLS-1$ + /** Default interpolator resource folder name, i.e. "interpolator" */ + public final static String FD_RES_INTERPOLATOR = "interpolator"; //$NON-NLS-1$ + /** Default layout resource folder name, i.e. "layout" */ + public final static String FD_RES_LAYOUT = "layout"; //$NON-NLS-1$ + /** Default menu resource folder name, i.e. "menu" */ + public final static String FD_RES_MENU = "menu"; //$NON-NLS-1$ + /** Default menu resource folder name, i.e. "mipmap" */ + public final static String FD_RES_MIPMAP = "mipmap"; //$NON-NLS-1$ + /** Default values resource folder name, i.e. "values" */ + public final static String FD_RES_VALUES = "values"; //$NON-NLS-1$ + /** Default xml resource folder name, i.e. "xml" */ + public final static String FD_RES_XML = "xml"; //$NON-NLS-1$ + /** Default raw resource folder name, i.e. "raw" */ + public final static String FD_RES_RAW = "raw"; //$NON-NLS-1$ + + /** Separator between the resource folder qualifier. */ + public final static String RES_QUALIFIER_SEP = "-"; //$NON-NLS-1$ + +} diff --git a/common/src/com/android/io/FileWrapper.java b/common/src/com/android/io/FileWrapper.java new file mode 100644 index 0000000..2859c0d --- /dev/null +++ b/common/src/com/android/io/FileWrapper.java @@ -0,0 +1,151 @@ +/* + * 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. + */ + +package com.android.io; + + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URI; + +/** + * An implementation of {@link IAbstractFile} extending {@link File}. + */ +public class FileWrapper extends File implements IAbstractFile { + private static final long serialVersionUID = 1L; + + /** + * Creates a new File instance matching a given {@link File} object. + * @param file the file to match + */ + public FileWrapper(File file) { + super(file.getAbsolutePath()); + } + + /** + * Creates a new File instance from a parent abstract pathname and a child pathname string. + * @param parent the parent pathname + * @param child the child name + * + * @see File#File(File, String) + */ + public FileWrapper(File parent, String child) { + super(parent, child); + } + + /** + * Creates a new File instance by converting the given pathname string into an abstract + * pathname. + * @param osPathname the OS pathname + * + * @see File#File(String) + */ + public FileWrapper(String osPathname) { + super(osPathname); + } + + /** + * Creates a new File instance from a parent abstract pathname and a child pathname string. + * @param parent the parent pathname + * @param child the child name + * + * @see File#File(String, String) + */ + public FileWrapper(String parent, String child) { + super(parent, child); + } + + /** + * Creates a new File instance by converting the given <code>file:</code> URI into an + * abstract pathname. + * @param uri An absolute, hierarchical URI with a scheme equal to "file", a non-empty path + * component, and undefined authority, query, and fragment components + * + * @see File#File(URI) + */ + public FileWrapper(URI uri) { + super(uri); + } + + public InputStream getContents() throws StreamException { + try { + return new FileInputStream(this); + } catch (FileNotFoundException e) { + throw new StreamException(e); + } + } + + public void setContents(InputStream source) throws StreamException { + FileOutputStream fos = null; + try { + fos = new FileOutputStream(this); + + byte[] buffer = new byte[1024]; + int count = 0; + while ((count = source.read(buffer)) != -1) { + fos.write(buffer, 0, count); + } + } catch (IOException e) { + throw new StreamException(e); + } finally { + if (fos != null) { + try { + fos.close(); + } catch (IOException e) { + throw new StreamException(e); + } + } + } + } + + public OutputStream getOutputStream() throws StreamException { + try { + return new FileOutputStream(this); + } catch (FileNotFoundException e) { + throw new StreamException(e); + } + } + + public PreferredWriteMode getPreferredWriteMode() { + return PreferredWriteMode.OUTPUTSTREAM; + } + + public String getOsLocation() { + return getAbsolutePath(); + } + + @Override + public boolean exists() { + return isFile(); + } + + public long getModificationStamp() { + return lastModified(); + } + + public IAbstractFolder getParentFolder() { + String p = this.getParent(); + if (p == null) { + return null; + } + return new FolderWrapper(p); + } +} diff --git a/common/src/com/android/io/FolderWrapper.java b/common/src/com/android/io/FolderWrapper.java new file mode 100644 index 0000000..26ed9cf --- /dev/null +++ b/common/src/com/android/io/FolderWrapper.java @@ -0,0 +1,154 @@ +/* + * 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. + */ + +package com.android.io; + + +import java.io.File; +import java.net.URI; +import java.util.ArrayList; + +/** + * An implementation of {@link IAbstractFolder} extending {@link File}. + */ +public class FolderWrapper extends File implements IAbstractFolder { + + private static final long serialVersionUID = 1L; + + /** + * Creates a new File instance from a parent abstract pathname and a child pathname string. + * @param parent the parent pathname + * @param child the child name + * + * @see File#File(File, String) + */ + public FolderWrapper(File parent, String child) { + super(parent, child); + } + + /** + * Creates a new File instance by converting the given pathname string into an abstract + * pathname. + * @param pathname the pathname + * + * @see File#File(String) + */ + public FolderWrapper(String pathname) { + super(pathname); + } + + /** + * Creates a new File instance from a parent abstract pathname and a child pathname string. + * @param parent the parent pathname + * @param child the child name + * + * @see File#File(String, String) + */ + public FolderWrapper(String parent, String child) { + super(parent, child); + } + + /** + * Creates a new File instance by converting the given <code>file:</code> URI into an + * abstract pathname. + * @param uri An absolute, hierarchical URI with a scheme equal to "file", a non-empty path + * component, and undefined authority, query, and fragment components + * + * @see File#File(URI) + */ + public FolderWrapper(URI uri) { + super(uri); + } + + /** + * Creates a new File instance matching a give {@link File} object. + * @param file the file to match + */ + public FolderWrapper(File file) { + super(file.getAbsolutePath()); + } + + public IAbstractResource[] listMembers() { + File[] files = listFiles(); + final int count = files == null ? 0 : files.length; + IAbstractResource[] afiles = new IAbstractResource[count]; + + if (files != null) { + for (int i = 0 ; i < count ; i++) { + File f = files[i]; + if (f.isFile()) { + afiles[i] = new FileWrapper(f); + } else if (f.isDirectory()) { + afiles[i] = new FolderWrapper(f); + } + } + } + + return afiles; + } + + public boolean hasFile(final String name) { + String[] match = list(new FilenameFilter() { + public boolean accept(IAbstractFolder dir, String filename) { + return name.equals(filename); + } + }); + + return match.length > 0; + } + + public IAbstractFile getFile(String name) { + return new FileWrapper(this, name); + } + + public IAbstractFolder getFolder(String name) { + return new FolderWrapper(this, name); + } + + public IAbstractFolder getParentFolder() { + String p = this.getParent(); + if (p == null) { + return null; + } + return new FolderWrapper(p); + } + + public String getOsLocation() { + return getAbsolutePath(); + } + + @Override + public boolean exists() { + return isDirectory(); + } + + public String[] list(FilenameFilter filter) { + File[] files = listFiles(); + if (files != null && files.length > 0) { + ArrayList<String> list = new ArrayList<String>(); + + for (File file : files) { + if (filter.accept(this, file.getName())) { + list.add(file.getName()); + } + } + + return list.toArray(new String[list.size()]); + } + + return new String[0]; + } +} diff --git a/common/src/com/android/io/IAbstractFile.java b/common/src/com/android/io/IAbstractFile.java new file mode 100644 index 0000000..6dfc8d8 --- /dev/null +++ b/common/src/com/android/io/IAbstractFile.java @@ -0,0 +1,58 @@ +/* + * 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. + */ + +package com.android.io; + +import java.io.InputStream; +import java.io.OutputStream; + +/** + * A file. + */ +public interface IAbstractFile extends IAbstractResource { + public static enum PreferredWriteMode { + INPUTSTREAM, OUTPUTSTREAM; + } + + /** + * Returns an {@link InputStream} object on the file content. + * @throws StreamException + */ + InputStream getContents() throws StreamException; + + /** + * Sets the content of the file. + * @param source the content + * @throws StreamException + */ + void setContents(InputStream source) throws StreamException; + + /** + * Returns an {@link OutputStream} to write into the file. + * @throws StreamException + */ + OutputStream getOutputStream() throws StreamException; + + /** + * Returns the preferred mode to write into the file. + */ + PreferredWriteMode getPreferredWriteMode(); + + /** + * Returns the last modification timestamp + */ + long getModificationStamp(); +} diff --git a/common/src/com/android/io/IAbstractFolder.java b/common/src/com/android/io/IAbstractFolder.java new file mode 100644 index 0000000..8335ef9 --- /dev/null +++ b/common/src/com/android/io/IAbstractFolder.java @@ -0,0 +1,77 @@ +/* + * 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. + */ + +package com.android.io; + +import java.io.File; + +/** + * A folder. + */ +public interface IAbstractFolder extends IAbstractResource { + /** + * Instances of classes that implement this interface are used to + * filter filenames. + */ + public interface FilenameFilter { + /** + * Tests if a specified file should be included in a file list. + * + * @param dir the directory in which the file was found. + * @param name the name of the file. + * @return <code>true</code> if and only if the name should be + * included in the file list; <code>false</code> otherwise. + */ + boolean accept(IAbstractFolder dir, String name); + } + + /** + * Returns true if the receiver contains a file with a given name + * @param name the name of the file. This is the name without the path leading to the + * parent folder. + */ + boolean hasFile(String name); + + /** + * Returns an {@link IAbstractFile} representing a child of the current folder with the + * given name. The file may not actually exist. + * @param name the name of the file. + */ + IAbstractFile getFile(String name); + + /** + * Returns an {@link IAbstractFolder} representing a child of the current folder with the + * given name. The folder may not actually exist. + * @param name the name of the folder. + */ + IAbstractFolder getFolder(String name); + + /** + * Returns a list of all existing file and directory members in this folder. + * The returned array can be empty but is never null. + */ + IAbstractResource[] listMembers(); + + /** + * Returns a list of all existing file and directory members in this folder + * that satisfy the specified filter. + * + * @param filter A filename filter instance. Must not be null. + * @return An array of file names (generated using {@link File#getName()}). + * The array can be empty but is never null. + */ + String[] list(FilenameFilter filter); +} diff --git a/common/src/com/android/io/IAbstractResource.java b/common/src/com/android/io/IAbstractResource.java new file mode 100644 index 0000000..3d762eb --- /dev/null +++ b/common/src/com/android/io/IAbstractResource.java @@ -0,0 +1,45 @@ +/* + * 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. + */ + +package com.android.io; + +/** + * Base representation of a file system resource.<p/> + * This somewhat limited interface is designed to let classes use file-system resources, without + * having the manually handle either the standard Java file or the Eclipse file API.. + */ +public interface IAbstractResource { + + /** + * Returns the name of the resource. + */ + String getName(); + + /** + * Returns the OS path of the folder location. + */ + String getOsLocation(); + + /** + * Returns whether the resource actually exists. + */ + boolean exists(); + + /** + * Returns the parent folder or null if there is no parent. + */ + IAbstractFolder getParentFolder(); +} diff --git a/common/src/com/android/io/StreamException.java b/common/src/com/android/io/StreamException.java new file mode 100644 index 0000000..f67c7a8 --- /dev/null +++ b/common/src/com/android/io/StreamException.java @@ -0,0 +1,28 @@ +/* + * 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.io; + +/** + * Exception thrown when {@link IAbstractFile#getContents()} fails. + */ +public class StreamException extends Exception { + private static final long serialVersionUID = 1L; + + public StreamException(Exception e) { + super(e); + } +} diff --git a/common/src/com/android/resources/FolderTypeRelationship.java b/common/src/com/android/resources/FolderTypeRelationship.java new file mode 100644 index 0000000..34961a3 --- /dev/null +++ b/common/src/com/android/resources/FolderTypeRelationship.java @@ -0,0 +1,164 @@ +/* + * Copyright (C) 2007 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; + + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * This class gives access to the bidirectional relationship between {@link ResourceType} and + * {@link ResourceFolderType}. + */ +public final class FolderTypeRelationship { + + private final static Map<ResourceType, List<ResourceFolderType>> mTypeToFolderMap = + new HashMap<ResourceType, List<ResourceFolderType>>(); + + private final static Map<ResourceFolderType, List<ResourceType>> mFolderToTypeMap = + new HashMap<ResourceFolderType, List<ResourceType>>(); + + static { + // generate the relationships in a temporary map + add(ResourceType.ANIM, ResourceFolderType.ANIM); + add(ResourceType.ANIMATOR, ResourceFolderType.ANIMATOR); + add(ResourceType.ARRAY, ResourceFolderType.VALUES); + add(ResourceType.ATTR, ResourceFolderType.VALUES); + add(ResourceType.BOOL, ResourceFolderType.VALUES); + add(ResourceType.COLOR, ResourceFolderType.VALUES); + add(ResourceType.COLOR, ResourceFolderType.COLOR); + add(ResourceType.DECLARE_STYLEABLE, ResourceFolderType.VALUES); + add(ResourceType.DIMEN, ResourceFolderType.VALUES); + add(ResourceType.DRAWABLE, ResourceFolderType.VALUES); + add(ResourceType.DRAWABLE, ResourceFolderType.DRAWABLE); + add(ResourceType.FRACTION, ResourceFolderType.VALUES); + add(ResourceType.ID, ResourceFolderType.VALUES); + add(ResourceType.INTEGER, ResourceFolderType.VALUES); + add(ResourceType.INTERPOLATOR, ResourceFolderType.INTERPOLATOR); + add(ResourceType.LAYOUT, ResourceFolderType.LAYOUT); + add(ResourceType.MENU, ResourceFolderType.MENU); + add(ResourceType.MIPMAP, ResourceFolderType.MIPMAP); + add(ResourceType.PLURALS, ResourceFolderType.VALUES); + add(ResourceType.PUBLIC, ResourceFolderType.VALUES); + add(ResourceType.RAW, ResourceFolderType.RAW); + add(ResourceType.STRING, ResourceFolderType.VALUES); + add(ResourceType.STYLE, ResourceFolderType.VALUES); + add(ResourceType.STYLEABLE, ResourceFolderType.VALUES); + add(ResourceType.XML, ResourceFolderType.XML); + + makeSafe(); + } + + /** + * Returns a list of {@link ResourceType}s that can be generated from files inside a folder + * of the specified type. + * @param folderType The folder type. + * @return a list of {@link ResourceType}, possibly empty but never null. + */ + public static List<ResourceType> getRelatedResourceTypes(ResourceFolderType folderType) { + List<ResourceType> list = mFolderToTypeMap.get(folderType); + if (list != null) { + return list; + } + + return Collections.emptyList(); + } + + /** + * Returns a list of {@link ResourceFolderType} that can contain files generating resources + * of the specified type. + * @param resType the type of resource. + * @return a list of {@link ResourceFolderType}, possibly empty but never null. + */ + public static List<ResourceFolderType> getRelatedFolders(ResourceType resType) { + List<ResourceFolderType> list = mTypeToFolderMap.get(resType); + if (list != null) { + return list; + } + + return Collections.emptyList(); + } + + /** + * Returns true if the {@link ResourceType} and the {@link ResourceFolderType} values match. + * @param resType the resource type. + * @param folderType the folder type. + * @return true if files inside the folder of the specified {@link ResourceFolderType} + * could generate a resource of the specified {@link ResourceType} + */ + public static boolean match(ResourceType resType, ResourceFolderType folderType) { + List<ResourceFolderType> list = mTypeToFolderMap.get(resType); + + if (list != null) { + return list.contains(folderType); + } + + return false; + } + + /** + * Adds a {@link ResourceType} - {@link ResourceFolderType} relationship. this indicates that + * a file in the folder can generate a resource of the specified type. + * @param type The resourceType + * @param folder The {@link ResourceFolderType} + */ + private static void add(ResourceType type, ResourceFolderType folder) { + // first we add the folder to the list associated with the type. + List<ResourceFolderType> folderList = mTypeToFolderMap.get(type); + if (folderList == null) { + folderList = new ArrayList<ResourceFolderType>(); + mTypeToFolderMap.put(type, folderList); + } + if (folderList.indexOf(folder) == -1) { + folderList.add(folder); + } + + // now we add the type to the list associated with the folder. + List<ResourceType> typeList = mFolderToTypeMap.get(folder); + if (typeList == null) { + typeList = new ArrayList<ResourceType>(); + mFolderToTypeMap.put(folder, typeList); + } + if (typeList.indexOf(type) == -1) { + typeList.add(type); + } + } + + /** + * Makes the maps safe by replacing the current list values with unmodifiable lists. + */ + private static void makeSafe() { + for (ResourceType type : ResourceType.values()) { + List<ResourceFolderType> list = mTypeToFolderMap.get(type); + if (list != null) { + // replace with a unmodifiable list wrapper around the current list. + mTypeToFolderMap.put(type, Collections.unmodifiableList(list)); + } + } + + for (ResourceFolderType folder : ResourceFolderType.values()) { + List<ResourceType> list = mFolderToTypeMap.get(folder); + if (list != null) { + // replace with a unmodifiable list wrapper around the current list. + mFolderToTypeMap.put(folder, Collections.unmodifiableList(list)); + } + } + } +} diff --git a/common/src/com/android/resources/ResourceFolderType.java b/common/src/com/android/resources/ResourceFolderType.java new file mode 100644 index 0000000..3a5b64d --- /dev/null +++ b/common/src/com/android/resources/ResourceFolderType.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2007 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; + +import com.android.AndroidConstants; + +/** + * Enum representing a type of resource folder. + */ +public enum ResourceFolderType { + ANIM(AndroidConstants.FD_RES_ANIM), + ANIMATOR(AndroidConstants.FD_RES_ANIMATOR), + COLOR(AndroidConstants.FD_RES_COLOR), + DRAWABLE(AndroidConstants.FD_RES_DRAWABLE), + INTERPOLATOR(AndroidConstants.FD_RES_INTERPOLATOR), + LAYOUT(AndroidConstants.FD_RES_LAYOUT), + MENU(AndroidConstants.FD_RES_MENU), + MIPMAP(AndroidConstants.FD_RES_MIPMAP), + RAW(AndroidConstants.FD_RES_RAW), + VALUES(AndroidConstants.FD_RES_VALUES), + XML(AndroidConstants.FD_RES_XML); + + private final String mName; + + ResourceFolderType(String name) { + mName = name; + } + + /** + * Returns the folder name for this resource folder type. + */ + public String getName() { + return mName; + } + + /** + * Returns the enum by name. + * @param name The enum string value. + * @return the enum or null if not found. + */ + public static ResourceFolderType getTypeByName(String name) { + for (ResourceFolderType rType : values()) { + if (rType.mName.equals(name)) { + return rType; + } + } + return null; + } + + /** + * Returns the {@link ResourceFolderType} from the folder name + * @param folderName The name of the folder. This must be a valid folder name in the format + * <code>resType[-resqualifiers[-resqualifiers[...]]</code> + * @return the <code>ResourceFolderType</code> representing the type of the folder, or + * <code>null</code> if no matching type was found. + */ + public static ResourceFolderType getFolderType(String folderName) { + // split the name of the folder in segments. + String[] folderSegments = folderName.split(AndroidConstants.RES_QUALIFIER_SEP); + + // get the enum for the resource type. + return getTypeByName(folderSegments[0]); + } +} diff --git a/common/src/com/android/resources/ResourceType.java b/common/src/com/android/resources/ResourceType.java index a4d3aa2..e9d4d53 100644 --- a/common/src/com/android/resources/ResourceType.java +++ b/common/src/com/android/resources/ResourceType.java @@ -1,11 +1,11 @@ /* * Copyright (C) 2007 The Android Open Source Project * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); + * 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.eclipse.org/org/documents/epl-v10.php + * 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, |