From b9c60624b1049409f0a000b6375fe3f65803ff74 Mon Sep 17 00:00:00 2001 From: Antonio Ospite <ospite@studenti.unina.it> Date: Sun, 24 Feb 2013 13:52:34 +0100 Subject: [PATCH] Initial import --- android-app-development-getting-started.sh | 85 ++++++++++++++++++ compile_and_run_app.sh | 23 +++++ ic_launcher_template/README.txt | 10 +++ ic_launcher_template/androink.py | 121 +++++++++++++++++++++++++ ic_launcher_template/ic_launcher.svg | 140 +++++++++++++++++++++++++++++ setenv | 4 + 6 files changed, 383 insertions(+) create mode 100755 android-app-development-getting-started.sh create mode 100755 compile_and_run_app.sh create mode 100644 ic_launcher_template/README.txt create mode 100755 ic_launcher_template/androink.py create mode 100644 ic_launcher_template/ic_launcher.svg create mode 100644 setenv diff --git a/android-app-development-getting-started.sh b/android-app-development-getting-started.sh new file mode 100755 index 0000000..971aa72 --- /dev/null +++ b/android-app-development-getting-started.sh @@ -0,0 +1,85 @@ +#!/usr/bin/env less +# +# Tutorial about getting started with android App development from the command +# line shell. +# +# Similar to +# http://vishalraj.in/blogs/hello-world-writing-my-first-android-app-on-linux +# + +# The base working dir is assumed to be $HOME/Android +mkdir $HOME/Android +cd $HOME/Android + +# Download and unpack the SDK from +# http://developer.android.com/sdk/index.html +wget http://dl.google.com/android/android-sdk_r21.1-linux.tgz +tar xzvf android-sdk_r21.1-linux.tgz + +# Add "platform-tools" and "tools" to the PATH +export ANDROID_HOME=$HOME/Android/android-sdk-linux +export PATH=$PATH:$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools + +# List packages +android list sdk --extended + +# Install packages. Use this same command line to update the packages +android update sdk --no-ui --filter platform-tools,android-17,sys-img-17,extra-android-support + +# Check what targets are available +android list targets + +# Create an Android Virtual Device (AVD) +android create avd --target android-17 --name android-17-x86 --abi x86 + +# Install "ant" to build packages +sudo aptitude install ant + +# Create a Hello World application +# http://developer.android.com/tools/projects/projects-cmdline.html +mkdir $HOME/Android/Apps +android create project \ + --target android-17 \ + --name MyFirstApp \ + --path $HOME/Android/Apps/MyFirstApp \ + --activity MainActivity \ + --package com.example.myfirstapp + +# And maybe you want to use git for your App? +cd $HOME/Android/Apps/MyFirstApp +ant clean +git init +git add . +git rm local.properties +git commit -m $'Initial import\n\nhttp://developer.android.com/training/basics/firstapp/creating-project.html' +echo "bin/" > .gitignore +echo "gen/" > .gitignore +echo "local.properties" > .gitignore +git add .gitignore +git commit -m "Add a .gitignore file" + +# Learn how to write Android Apps: +http://developer.android.com/training/basics/firstapp/building-ui.html + +# Build the App +# http://developer.android.com/tools/building/building-cmdline.html +cd $HOME/Android/Apps/MyFirstApp +ant debug + +# Start the emulator, hardware accelerated: +# http://developer.android.com/tools/devices/emulator.html#vm-linux +emulator -verbose -avd android-17-x86 -scale 0.9 -gpu on -qemu -m 512 -enable-kvm + +# Install the App into an Android [Virtual] Device +adb devices -l +adb -s emulator-5554 install bin/MyFirstApp-debug.apk + +# Launch your application from the HOST +adb -s emulator-5554 -e shell am start -a android.intent.action.MAIN -n com.example.myfirstapp/com.example.myfirstapp.MainActivity + +# See logs, e.g. only errors +adb -s emulator-5554 logcat *:E + +# Connect to the emulator via telnet if needed +telnet localhost 5554 + diff --git a/compile_and_run_app.sh b/compile_and_run_app.sh new file mode 100755 index 0000000..306d535 --- /dev/null +++ b/compile_and_run_app.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +set -e + +if command -v xmllint >/dev/null 2>&1; +then + # Try xmllint from the "xmllint" package + XPATH="xmllint --xpath " +elif command -v xpath >/dev/null 2>&1; +then + # xpath is from the perl XML::XPath module: libxml-xpath-perl package + XPATH="xpath -e" +else + { echo "Install either xmllint or the XML::XPath perl module" 1>&2; exit 1; } +fi + +APP_NAME=$($XPATH "string(//project/@name)" build.xml) +PACKAGE=$($XPATH "string(//manifest/@package)" AndroidManifest.xml) +MAIN_ACTIVITY=$($XPATH "string(//activity[1]/@*[local-name() = 'name'])" AndroidManifest.xml) + +ant debug +adb -s emulator-5554 install -r bin/${APP_NAME}-debug.apk +adb -s emulator-5554 -e shell am start -a android.intent.action.MAIN -n ${PACKAGE}/${PACKAGE}.${MAIN_ACTIVITY} diff --git a/ic_launcher_template/README.txt b/ic_launcher_template/README.txt new file mode 100644 index 0000000..83e7f9a --- /dev/null +++ b/ic_launcher_template/README.txt @@ -0,0 +1,10 @@ +The template provided here is 48x48 px with a border of 1/12 of the size. +http://tekeye.biz/2012/android-launcher-icons-using-inkscape + +The exporter script will generate icons at 36x36, 48x48, 72x72, 96x96 pixels + +The androink.py export script is an evolution of: +https://gist.github.com/fedepaol/4127778 + +And alternative is to use the android4inkscape extension: +https://github.com/kengoodridge/android4inkscape diff --git a/ic_launcher_template/androink.py b/ic_launcher_template/androink.py new file mode 100755 index 0000000..c8a83bd --- /dev/null +++ b/ic_launcher_template/androink.py @@ -0,0 +1,121 @@ +#!/usr/bin/env python +# +# androink - Generate android resources for multiple resolutions +# +# Copyright (C) 2012 Federico Paolinelli <fedepaol@gmail.com> +# Copyright (C) 2013 Antonio Ospite <ospite@studenti.unina.it> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# Based on: +# https://gist.github.com/fedepaol/4127778 +# +# Following the directions of: +# https://developer.android.com/guide/practices/screens_support.html + +import argparse +import sys +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. + +""" +__version = "0.1" +__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 +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) + +resolutions = [LDPI, MDPI, HDPI, XHDPI] + + +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 + res_path = os.path.join(args.res_folder, dpispec) + + if not os.path.exists(res_path): + os.makedirs(res_path) + + source_file = os.path.join(args.svg_folder, file_name) + target = os.path.join(res_path, name_without_ext + '.png') + + command_list = [args.ink_path, '--export-area-page', + '-f', source_file, + '--export-png', target, + '--export-dpi', str(dpi)] + + command = " ".join(command_list) + + print 'executing', command + if not args.dry: + os.popen(command) + + +def option_parser(): + usage = "usage: %(prog)s [options]" + + parser = argparse.ArgumentParser(usage=usage, + description=__description, + epilog=__author_info, + version='%(prog)s ' + __version,) + + parser.add_argument('-R', '--res_folder', metavar="<dir>", + dest='res_folder', required=True, + help='path to the project res folder') + + parser.add_argument('-S', '--svg_folder', metavar="<dir>", + dest='svg_folder', default='.', + help='folder that contains all the svg files to be converted') + + parser.add_argument('-I', '--inkscape_path', metavar="<inkscape_path>", + dest='ink_path', default='inkscape', + help='path of Inkscape executable') + + parser.add_argument('-D', '--dry_run', + dest='dry', action='store_const', const=True, + help='performs a dry run') + + parser.add_argument('-F', '--single_file', metavar="<file>", + dest='file_name', + help='name of the file, if you want to convert only one file') + + return parser + + +if __name__ == "__main__": + parser = option_parser() + args = parser.parse_args() + + if args.file_name: + export_file(args.file_name) + else: + files = os.listdir(args.svg_folder) + svg_files = filter(lambda x: x.lower().endswith('.svg'), files) + + map(export_file, svg_files) diff --git a/ic_launcher_template/ic_launcher.svg b/ic_launcher_template/ic_launcher.svg new file mode 100644 index 0000000..a25c3ed --- /dev/null +++ b/ic_launcher_template/ic_launcher.svg @@ -0,0 +1,140 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:xlink="http://www.w3.org/1999/xlink" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="48" + height="48" + id="svg2" + version="1.1" + inkscape:version="0.48.3.1 r9886" + sodipodi:docname="ic_launcher.svg"> + <defs + id="defs4"> + <linearGradient + id="linearGradient4114"> + <stop + style="stop-color:#ffffff;stop-opacity:1;" + offset="0" + id="stop4116" /> + <stop + id="stop4118" + offset="0.36040047" + style="stop-color:#e2f2b0;stop-opacity:1" /> + <stop + style="stop-color:#c6e26e;stop-opacity:1" + offset="0.38111261" + id="stop4120" /> + <stop + id="stop4122" + offset="0.53974605" + style="stop-color:#b6d850;stop-opacity:1" /> + <stop + style="stop-color:#accf45;stop-opacity:1" + offset="0.55895942" + id="stop4124" /> + <stop + style="stop-color:#a4c639;stop-opacity:1" + offset="1" + id="stop4126" /> + </linearGradient> + <filter + inkscape:collect="always" + id="filter3964"> + <feGaussianBlur + inkscape:collect="always" + stdDeviation="3.392857" + id="feGaussianBlur3966" /> + </filter> + <radialGradient + inkscape:collect="always" + xlink:href="#linearGradient4114" + id="radialGradient3038" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(-0.27111876,0.50302922,-0.53215558,-0.2868171,694.31841,1062.4433)" + spreadMethod="pad" + cx="473.27908" + cy="1001.8383" + fx="473.27908" + fy="1001.8383" + r="92.698822" /> + </defs> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="10.770833" + inkscape:cx="22.069541" + inkscape:cy="26.082356" + inkscape:document-units="px" + inkscape:current-layer="layer1" + showgrid="false" + inkscape:window-width="1152" + inkscape:window-height="756" + inkscape:window-x="0" + inkscape:window-y="29" + inkscape:window-maximized="1" + showguides="true" + inkscape:guide-bbox="true"> + <sodipodi:guide + orientation="1,0" + position="4,0" + id="guide3004" /> + <sodipodi:guide + orientation="0,1" + position="0,4" + id="guide3006" /> + <sodipodi:guide + orientation="0,1" + position="0,44" + id="guide3008" /> + <sodipodi:guide + orientation="1,0" + position="44,0" + id="guide3010" /> + </sodipodi:namedview> + <metadata + id="metadata7"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title /> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1" + transform="translate(0,-1004.3622)"> + <path + transform="matrix(0.28713525,0,0,0.28713525,24.820386,1008.0319)" + d="m 64.999997,74.285713 a 67.85714,67.85714 0 1 1 -135.71428,0 67.85714,67.85714 0 1 1 135.71428,0 z" + sodipodi:ry="67.85714" + sodipodi:rx="67.85714" + sodipodi:cy="74.285713" + sodipodi:cx="-2.8571429" + id="path2433-3" + style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1.15276682;marker:none;visibility:visible;display:inline;overflow:visible;filter:url(#filter3964);enable-background:accumulate" + sodipodi:type="arc" /> + <path + sodipodi:nodetypes="sssss" + style="fill:url(#radialGradient3038);fill-opacity:1;stroke:#9fbc44;stroke-width:0.44435024;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:5.19999981;stroke-opacity:1;stroke-dasharray:none;display:inline" + d="m 23.999997,1008.5843 c -10.325704,0 -19.7778222,9.4521 -19.7778222,19.7779 0,10.3257 9.4521182,19.7778 19.7778222,19.7778 10.325706,0 19.777827,-9.4521 19.777827,-19.7778 0,-10.3258 -9.452121,-19.7779 -19.777827,-19.7779 z" + id="path2435" + inkscape:connector-curvature="0" /> + </g> +</svg> diff --git a/setenv b/setenv new file mode 100644 index 0000000..5b85830 --- /dev/null +++ b/setenv @@ -0,0 +1,4 @@ +#!/bin/sh +# This file is meant to be sourced, not executed. +export ANDROID_HOME=$HOME/Android/android-sdk-linux +export PATH=$PATH:$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools -- 2.1.4