Move from arbitrary resource filters to fix ones
Resource filters are used when generating additional APK containing only specific resources. The previous UI allowed for any type of filters, but we are moving to a simpler way with fixed filters. The first one is the density. Selecting the filter will generate 4 APKs per application: default (all resources), hdpi (only hdpi/nodpi and default resources), mdpi, ldpi.
This commit is contained in:
@@ -16,91 +16,33 @@
|
||||
|
||||
package com.android.sdklib.internal.project;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
* Helper class to read and write Apk Configuration into a {@link ProjectProperties} file.
|
||||
*/
|
||||
public class ApkConfigurationHelper {
|
||||
/** Prefix for property names for config definition. This prevents having config named
|
||||
* after other valid properties such as "target". */
|
||||
final static String CONFIG_PREFIX = "apk-config-";
|
||||
|
||||
/**
|
||||
* Reads the Apk Configurations from a {@link ProjectProperties} file and returns them as a map.
|
||||
* <p/>If there are no defined configurations, the returned map will be empty.
|
||||
* @return a map of apk configurations. The map contains (name, filter) where name is
|
||||
* the name of the configuration (a-zA-Z0-9 only), and filter is the comma separated list of
|
||||
* resource configuration to include in the apk (see aapt -c)
|
||||
* Reads the project settings from a {@link ProjectProperties} file and returns them as a
|
||||
* {@link ApkSettings} object.
|
||||
*/
|
||||
public static Map<String, String> getConfigs(ProjectProperties properties) {
|
||||
HashMap<String, String> configMap = new HashMap<String, String>();
|
||||
public static ApkSettings getSettings(ProjectProperties properties) {
|
||||
ApkSettings apkSettings = new ApkSettings();
|
||||
|
||||
// get the list of configs.
|
||||
String configList = properties.getProperty(ProjectProperties.PROPERTY_APK_CONFIGS);
|
||||
if (configList != null) {
|
||||
// this is a comma separated list
|
||||
String[] configs = configList.split(","); //$NON-NLS-1$
|
||||
|
||||
// read the value of each config and store it in a map
|
||||
for (String config : configs) {
|
||||
config = config.trim();
|
||||
String configValue = properties.getProperty(CONFIG_PREFIX + config);
|
||||
if (configValue != null) {
|
||||
configMap.put(config, configValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return configMap;
|
||||
boolean splitByDensity = Boolean.parseBoolean(properties.getProperty(
|
||||
ProjectProperties.PROPERTY_SPLIT_BY_DENSITY));
|
||||
apkSettings.setSplitByDensity(splitByDensity);
|
||||
|
||||
|
||||
return apkSettings;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Writes the Apk Configurations from a given map into a {@link ProjectProperties}.
|
||||
* @param properties the {@link ProjectProperties} in which to store the apk configurations.
|
||||
* @param configMap a map of apk configurations. The map contains (name, filter) where name is
|
||||
* the name of the configuration (a-zA-Z0-9 only), and filter is the comma separated list of
|
||||
* resource configuration to include in the apk (see aapt -c)
|
||||
* @return true if the {@link ProjectProperties} contained Apk Configuration that were not
|
||||
* present in the map.
|
||||
* Sets the content of a {@link ApkSettings} into a {@link ProjectProperties}.
|
||||
* @param properties the {@link ProjectProperties} in which to store the settings.
|
||||
* @param settings the project settings to store.
|
||||
*/
|
||||
public static boolean setConfigs(ProjectProperties properties, Map<String, String> configMap) {
|
||||
// load the current configs, in order to remove the value properties for each of them
|
||||
// in case a config was removed.
|
||||
|
||||
// get the list of configs.
|
||||
String configList = properties.getProperty(ProjectProperties.PROPERTY_APK_CONFIGS);
|
||||
|
||||
boolean hasRemovedConfig = false;
|
||||
|
||||
if (configList != null) {
|
||||
// this is a comma separated list
|
||||
String[] configs = configList.split(","); //$NON-NLS-1$
|
||||
|
||||
for (String config : configs) {
|
||||
config = config.trim();
|
||||
if (configMap.containsKey(config) == false) {
|
||||
hasRemovedConfig = true;
|
||||
properties.removeProperty(CONFIG_PREFIX + config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// now add the properties.
|
||||
Set<Entry<String, String>> entrySet = configMap.entrySet();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Entry<String, String> entry : entrySet) {
|
||||
if (sb.length() > 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append(entry.getKey());
|
||||
properties.setProperty(CONFIG_PREFIX + entry.getKey(), entry.getValue());
|
||||
}
|
||||
properties.setProperty(ProjectProperties.PROPERTY_APK_CONFIGS, sb.toString());
|
||||
|
||||
return hasRemovedConfig;
|
||||
public static void setProperties(ProjectProperties properties, ApkSettings settings) {
|
||||
properties.setProperty(ProjectProperties.PROPERTY_SPLIT_BY_DENSITY,
|
||||
Boolean.toString(settings.isSplitByDpi()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (C) 2009 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.sdklib.internal.project;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Settings for multiple APK generation.
|
||||
*/
|
||||
public class ApkSettings {
|
||||
private boolean mSplitByDpi = false;
|
||||
|
||||
public ApkSettings() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map of configuration filters to be used by the -c option of aapt.
|
||||
* <p/>The map stores (key, value) pairs where the keys is a filename modifier and the value
|
||||
* is the parameter to pass to aapt through the -c option.
|
||||
* @return a map, always. It can however be empty.
|
||||
*/
|
||||
public Map<String, String> getResourceFilters() {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
if (mSplitByDpi) {
|
||||
map.put("hdpi", "hdpi,nodpi");
|
||||
map.put("mdpi", "mdpi,nodpi");
|
||||
map.put("ldpi", "ldpi,nodpi");
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether APKs should be generate for each dpi level.
|
||||
*/
|
||||
public boolean isSplitByDpi() {
|
||||
return mSplitByDpi;
|
||||
}
|
||||
|
||||
public void setSplitByDensity(boolean split) {
|
||||
mSplitByDpi = split;
|
||||
}
|
||||
}
|
||||
@@ -35,14 +35,17 @@ import java.util.Map.Entry;
|
||||
public final class ProjectProperties {
|
||||
/** The property name for the project target */
|
||||
public final static String PROPERTY_TARGET = "target";
|
||||
public final static String PROPERTY_APK_CONFIGS = "apk.configurations";
|
||||
|
||||
public final static String PROPERTY_SDK = "sdk.dir";
|
||||
// LEGACY - compatibility with 1.6 and before
|
||||
public final static String PROPERTY_SDK_LEGACY = "sdk-location";
|
||||
|
||||
public final static String PROPERTY_APP_PACKAGE = "application.package";
|
||||
// LEGACY - compatibility with 1.6 and before
|
||||
public final static String PROPERTY_APP_PACKAGE_LEGACY = "application-package";
|
||||
|
||||
public final static String PROPERTY_SPLIT_BY_DENSITY = "split.density";
|
||||
|
||||
public static enum PropertyType {
|
||||
BUILD("build.properties", BUILD_HEADER),
|
||||
DEFAULT("default.properties", DEFAULT_HEADER),
|
||||
@@ -107,17 +110,8 @@ public final class ProjectProperties {
|
||||
// 1-------10--------20--------30--------40--------50--------60--------70--------80
|
||||
COMMENT_MAP.put(PROPERTY_TARGET,
|
||||
"# Project target.\n");
|
||||
COMMENT_MAP.put(PROPERTY_APK_CONFIGS,
|
||||
"# apk configurations. This property allows creation of APK files with limited\n" +
|
||||
"# resources. For example, if your application contains many locales and\n" +
|
||||
"# you wish to release multiple smaller apks instead of a large one, you can\n" +
|
||||
"# define configuration to create apks with limited language sets.\n" +
|
||||
"# Format is a comma separated list of configuration names. For each\n" +
|
||||
"# configuration, a property will declare the resource configurations to\n" +
|
||||
"# include. Example:\n" +
|
||||
"# " + PROPERTY_APK_CONFIGS +"=european,northamerica\n" +
|
||||
"# " + ApkConfigurationHelper.CONFIG_PREFIX + "european=en,fr,it,de,es\n" +
|
||||
"# " + ApkConfigurationHelper.CONFIG_PREFIX + "northamerica=en,es\n");
|
||||
COMMENT_MAP.put(PROPERTY_SPLIT_BY_DENSITY,
|
||||
"# Indicates whether an apk should be generated for each density.\n");
|
||||
COMMENT_MAP.put(PROPERTY_SDK,
|
||||
"# location of the SDK. This is only used by Ant\n" +
|
||||
"# For customization when using a Version Control System, please read the\n" +
|
||||
|
||||
Reference in New Issue
Block a user