Home | History | Annotate | Download | only in project
      1 /*
      2  * Copyright (C) 2009 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.sdklib.internal.project;
     18 
     19 import java.util.HashMap;
     20 import java.util.Map;
     21 
     22 /**
     23  * Settings for multiple APK generation.
     24  */
     25 public class ApkSettings {
     26     private boolean mSplitByDpi = false;
     27 
     28     public ApkSettings() {
     29     }
     30 
     31     /**
     32      * Creates an ApkSettings and fills it from the project settings read from a
     33      * {@link ProjectProperties} file.
     34      */
     35     public ApkSettings(ProjectProperties properties) {
     36         boolean splitByDensity = Boolean.parseBoolean(properties.getProperty(
     37                 ProjectProperties.PROPERTY_SPLIT_BY_DENSITY));
     38         setSplitByDensity(splitByDensity);
     39     }
     40 
     41     /**
     42      * Returns a map of configuration filters to be used by the -c option of aapt.
     43      * <p/>The map stores (key, value) pairs where the keys is a filename modifier and the value
     44      * is the parameter to pass to aapt through the -c option.
     45      * @return a map, always. It can however be empty.
     46      */
     47     public Map<String, String> getResourceFilters() {
     48         Map<String, String> map = new HashMap<String, String>();
     49         if (mSplitByDpi) {
     50             map.put("hdpi", "hdpi,nodpi");
     51             map.put("mdpi", "mdpi,nodpi");
     52             map.put("ldpi", "ldpi,nodpi");
     53         }
     54 
     55         return map;
     56     }
     57 
     58     /**
     59      * Indicates whether APKs should be generate for each dpi level.
     60      */
     61     public boolean isSplitByDpi() {
     62         return mSplitByDpi;
     63     }
     64 
     65     public void setSplitByDensity(boolean split) {
     66         mSplitByDpi = split;
     67     }
     68 
     69     /**
     70      * Writes the receiver into a {@link ProjectProperties}.
     71      * @param properties the {@link ProjectProperties} in which to store the settings.
     72      */
     73     public void write(ProjectProperties properties) {
     74         // TODO: this is not supported at the moment, so we dont write the property into the file.
     75 //        propertiessetProperty(ProjectProperties.PROPERTY_SPLIT_BY_DENSITY,
     76 //                Boolean.toString(isSplitByDpi()));
     77     }
     78 
     79     @Override
     80     public boolean equals(Object obj) {
     81         if (obj instanceof ApkSettings) {
     82             return mSplitByDpi == ((ApkSettings) obj).mSplitByDpi;
     83         }
     84 
     85         return false;
     86     }
     87 
     88     @Override
     89     public int hashCode() {
     90         return Boolean.valueOf(mSplitByDpi).hashCode();
     91     }
     92 }
     93