From: Antonio Ospite Date: Wed, 11 Sep 2013 21:30:53 +0000 (+0200) Subject: androink.py: support both mdpi and hdpi as baseline densities X-Git-Url: https://git.ao2.it/android/android-app-development-getting-started.git/commitdiff_plain/f89fcf538f649bac70084a1a51d3e58a196e71c3?ds=sidebyside;hp=b6a9443f919b274097da17757ef9afebf80731f5 androink.py: support both mdpi and hdpi as baseline densities Also replace the word "resolutions" with "density" which is more accurate in this context. --- diff --git a/ic_launcher_template/androink.py b/ic_launcher_template/androink.py index a423b7b..efb9356 100755 --- a/ic_launcher_template/androink.py +++ b/ic_launcher_template/androink.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# androink - Generate android resources for multiple resolutions +# androink - Generate android resources for multiple densities # # Copyright (C) 2012 Federico Paolinelli # Copyright (C) 2013 Antonio Ospite @@ -30,8 +30,8 @@ import os __description = """This script expects the svg to use Inkscape DPIs. -This means that the resolution given in the drawing will be used for -MDPI resolution and scaled to generate the other resolutions. +Either MDPI or HDPI can be used as the baseline density and the drawables will +scaled to generate the other densities. """ __version = "0.1" @@ -40,23 +40,40 @@ __author_info = "Federico Paolinelli, Antonio Ospite" BASE_OPTIONS = ' --export-area-page --export-png ' -# Inkscape default DPI is 90, we use this for the MDPI resource +# Inkscape default DPI is 90 BASELINE_DPI = 90 -LDPI = ('drawable-ldpi', BASELINE_DPI * 0.75) -MDPI = ('drawable-mdpi', BASELINE_DPI * 1.0) -HDPI = ('drawable-hdpi', BASELINE_DPI * 1.5) -XHDPI = ('drawable-xhdpi', BASELINE_DPI * 2.0) +# densities are calculated following the scaling ratio +# 3:4:6:8 mapped to ldpi:mdpi:hdpi:xhdpi -resolutions = [LDPI, MDPI, HDPI, XHDPI] +# for baseline mdpi consider 4 as the base ratio +densities_baseline_mdpi = [ + ('drawable-ldpi', BASELINE_DPI * 0.75), # 3/4 + ('drawable-mdpi', BASELINE_DPI * 1.0), # 4/4 + ('drawable-hdpi', BASELINE_DPI * 1.5), # 6/4 + ('drawable-xhdpi', BASELINE_DPI * 2.0), # 8/4 + ] + +# for baseline hdpi consider 6 as the base ratio +densities_baseline_hdpi = [ + ('drawable-ldpi', BASELINE_DPI * 0.5), # 3/6 + ('drawable-mdpi', BASELINE_DPI * 0.666666667), # 4/6 + ('drawable-hdpi', BASELINE_DPI * 1.0), # 6/6 + ('drawable-xhdpi', BASELINE_DPI * 1.333333333), # 8/6 + ] def export_file(file_name): print 'exporting file', file_name name_without_ext = os.path.splitext(file_name)[0] - for rel in resolutions: - dpispec, dpi = rel + if args.baseline_density == 'mdpi': + densities = densities_baseline_mdpi + elif args.baseline_density == 'hdpi': + densities = densities_baseline_hdpi + + for density in densities: + dpispec, dpi = density res_path = os.path.join(args.res_folder, dpispec) if not os.path.exists(res_path): @@ -97,6 +114,10 @@ def option_parser(): dest='ink_path', default='inkscape', help='path of Inkscape executable') + parser.add_argument('-d', '--baseline-density', metavar="", + dest='baseline_density', choices=['mdpi', 'hdpi'], default='mdpi', + help='the baseline density to generate the drawables from') + parser.add_argument('-D', '--dry_run', dest='dry', action='store_const', const=True, help='performs a dry run')