aboutsummaryrefslogtreecommitdiffstats
path: root/layoutopt/app
diff options
context:
space:
mode:
authorAndroid (Google) Code Review <android-gerrit@google.com>2009-10-05 07:13:21 -0400
committerAndroid (Google) Code Review <android-gerrit@google.com>2009-10-05 07:13:21 -0400
commit0cbd47a86156fbfc411c5e0990695ffd6568f47f (patch)
treee794ecdddfab4ebf7f56cca3c82a423e93a54cd7 /layoutopt/app
parent9753171cffd39fbc46299c23aac94e963652f892 (diff)
parentc49990616a2c36e5a8d221712ae5ef94a06be793 (diff)
downloadsdk-0cbd47a86156fbfc411c5e0990695ffd6568f47f.zip
sdk-0cbd47a86156fbfc411c5e0990695ffd6568f47f.tar.gz
sdk-0cbd47a86156fbfc411c5e0990695ffd6568f47f.tar.bz2
Merge change I8e4697e1 into eclair
* changes: New layout optimization tool. Run layoutopt on the command line.
Diffstat (limited to 'layoutopt/app')
-rw-r--r--layoutopt/app/Android.mk5
-rw-r--r--layoutopt/app/README3
-rw-r--r--layoutopt/app/etc/Android.mk8
-rwxr-xr-xlayoutopt/app/etc/layoutopt63
-rwxr-xr-xlayoutopt/app/etc/layoutopt.bat48
-rw-r--r--layoutopt/app/etc/manifest.txt2
-rw-r--r--layoutopt/app/src/Android.mk15
-rw-r--r--layoutopt/app/src/com/android/layoutopt/cli/Main.java123
8 files changed, 267 insertions, 0 deletions
diff --git a/layoutopt/app/Android.mk b/layoutopt/app/Android.mk
new file mode 100644
index 0000000..3fae340
--- /dev/null
+++ b/layoutopt/app/Android.mk
@@ -0,0 +1,5 @@
+# Copyright 2009 The Android Open Source Project
+#
+LAYOUTOPT_LOCAL_DIR := $(call my-dir)
+include $(LAYOUTOPT_LOCAL_DIR)/etc/Android.mk
+include $(LAYOUTOPT_LOCAL_DIR)/src/Android.mk
diff --git a/layoutopt/app/README b/layoutopt/app/README
new file mode 100644
index 0000000..c118022
--- /dev/null
+++ b/layoutopt/app/README
@@ -0,0 +1,3 @@
+Layout optimizer.
+
+Simple command line front end for the uix library. \ No newline at end of file
diff --git a/layoutopt/app/etc/Android.mk b/layoutopt/app/etc/Android.mk
new file mode 100644
index 0000000..ae08f9d
--- /dev/null
+++ b/layoutopt/app/etc/Android.mk
@@ -0,0 +1,8 @@
+# Copyright 2009 The Android Open Source Project
+#
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_PREBUILT_EXECUTABLES := layoutopt
+include $(BUILD_HOST_PREBUILT)
+
diff --git a/layoutopt/app/etc/layoutopt b/layoutopt/app/etc/layoutopt
new file mode 100755
index 0000000..22ebb67
--- /dev/null
+++ b/layoutopt/app/etc/layoutopt
@@ -0,0 +1,63 @@
+#!/bin/sh
+# Copyright 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.
+
+# Set up prog to be the path of this script, including following symlinks,
+# and set up progdir to be the fully-qualified pathname of its directory.
+prog="$0"
+while [ -h "${prog}" ]; do
+ newProg=`/bin/ls -ld "${prog}"`
+ newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
+ if expr "x${newProg}" : 'x/' >/dev/null; then
+ prog="${newProg}"
+ else
+ progdir=`dirname "${prog}"`
+ prog="${progdir}/${newProg}"
+ fi
+done
+oldwd=`pwd`
+progdir=`dirname "${prog}"`
+cd "${progdir}"
+progdir=`pwd`
+prog="${progdir}"/`basename "${prog}"`
+cd "${oldwd}"
+
+jarfile=layoutopt.jar
+frameworkdir="$progdir"
+if [ ! -r "$frameworkdir/$jarfile" ]
+then
+ frameworkdir=`dirname "$progdir"`/tools/lib
+ libdir=`dirname "$progdir"`/tools/lib
+fi
+if [ ! -r "$frameworkdir/$jarfile" ]
+then
+ frameworkdir=`dirname "$progdir"`/framework
+ libdir=`dirname "$progdir"`/lib
+fi
+if [ ! -r "$frameworkdir/$jarfile" ]
+then
+ echo `basename "$prog"`": can't find $jarfile"
+ exit 1
+fi
+
+if [ "$OSTYPE" = "cygwin" ] ; then
+ jarpath=`cygpath -w "$frameworkdir/$jarfile"`
+ progdir=`cygpath -w "$progdir"`
+else
+ jarpath="$frameworkdir/$jarfile"
+fi
+
+# need to use "java.ext.dirs" because "-jar" causes classpath to be ignored
+# might need more memory, e.g. -Xmx128M
+exec java -Djava.ext.dirs="$frameworkdir" -jar "$jarpath" "$@"
diff --git a/layoutopt/app/etc/layoutopt.bat b/layoutopt/app/etc/layoutopt.bat
new file mode 100755
index 0000000..e1eb7b3
--- /dev/null
+++ b/layoutopt/app/etc/layoutopt.bat
@@ -0,0 +1,48 @@
+@echo off
+rem Copyright (C) 2009 The Android Open Source Project
+rem
+rem Licensed under the Apache License, Version 2.0 (the "License");
+rem you may not use this file except in compliance with the License.
+rem You may obtain a copy of the License at
+rem
+rem http://www.apache.org/licenses/LICENSE-2.0
+rem
+rem Unless required by applicable law or agreed to in writing, software
+rem distributed under the License is distributed on an "AS IS" BASIS,
+rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+rem See the License for the specific language governing permissions and
+rem limitations under the License.
+
+rem don't modify the caller's environment
+setlocal
+
+rem Set up prog to be the path of this script, including following symlinks,
+rem and set up progdir to be the fully-qualified pathname of its directory.
+set prog=%~f0
+
+rem Change current directory and drive to where the script is, to avoid
+rem issues with directories containing whitespaces.
+cd /d %~dp0
+
+set jarfile=layoutopt.jar
+set frameworkdir=
+
+if exist %frameworkdir%%jarfile% goto JarFileOk
+ set frameworkdir=lib\
+
+if exist %frameworkdir%%jarfile% goto JarFileOk
+ set frameworkdir=..\framework\
+
+:JarFileOk
+
+if debug NEQ "%1" goto NoDebug
+ set java_debug=-agentlib:jdwp=transport=dt_socket,server=y,address=8050,suspend=y
+ shift 1
+:NoDebug
+
+set jarpath=%frameworkdir%%jarfile%
+
+set javaextdirs=%swt_path%;%frameworkdir%
+
+call java %java_debug% -Djava.ext.dirs=%javaextdirs% %jarpath% %*
+
diff --git a/layoutopt/app/etc/manifest.txt b/layoutopt/app/etc/manifest.txt
new file mode 100644
index 0000000..5d0afdf
--- /dev/null
+++ b/layoutopt/app/etc/manifest.txt
@@ -0,0 +1,2 @@
+Main-Class: com.android.layoutopt.cli.Main
+Class-Path: groovy-all-1.6.5.jar
diff --git a/layoutopt/app/src/Android.mk b/layoutopt/app/src/Android.mk
new file mode 100644
index 0000000..131addd
--- /dev/null
+++ b/layoutopt/app/src/Android.mk
@@ -0,0 +1,15 @@
+# Copyright 2009 The Android Open Source Project
+#
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-subdir-java-files)
+LOCAL_JAVA_RESOURCE_DIRS := resources
+
+LOCAL_JAR_MANIFEST := ../etc/manifest.txt
+LOCAL_JAVA_LIBRARIES := \
+ uix
+LOCAL_MODULE := layoutopt
+
+include $(BUILD_HOST_JAVA_LIBRARY)
+
diff --git a/layoutopt/app/src/com/android/layoutopt/cli/Main.java b/layoutopt/app/src/com/android/layoutopt/cli/Main.java
new file mode 100644
index 0000000..9b3b9aa
--- /dev/null
+++ b/layoutopt/app/src/com/android/layoutopt/cli/Main.java
@@ -0,0 +1,123 @@
+/*
+ * 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.layoutopt.cli;
+
+import com.android.layoutopt.uix.LayoutAnalyzer;
+import com.android.layoutopt.uix.LayoutAnalysis;
+
+import java.io.File;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * Command line utility for the uix library.
+ *
+ * This is a simple CLI front-end for the uix library, used to
+ * analyze and optimize Android layout files.
+ */
+public class Main {
+ /**
+ * Main entry point of the application.
+ *
+ * @param args One mandatory parameter, a path (absolute or relative)
+ * to an Android XML layout file
+ */
+ public static void main(String[] args) {
+ Parameters p = checkParameters(args);
+ if (!p.valid) {
+ displayHelpMessage();
+ exit();
+ }
+
+ analyzeFiles(p.files);
+ }
+
+ private static void analyzeFiles(File[] files) {
+ LayoutAnalyzer analyzer = new LayoutAnalyzer();
+ for (File file : files) {
+ if (file.isFile()) {
+ analyze(analyzer, file);
+ } else {
+ analyzeFiles(file.listFiles());
+ }
+ }
+ }
+
+ private static void analyze(LayoutAnalyzer analyzer, File file) {
+ LayoutAnalysis analysis = analyzer.analyze(file);
+ System.out.println(analysis.getName());
+ for (LayoutAnalysis.Issue issue : analysis.getIssues()) {
+ System.out.print(String.format("\t%d:%d ", issue.getStartLine(), issue.getEndLine()));
+ System.out.println(issue.getDescription());
+ }
+ }
+
+ /**
+ * Exits the tool.
+ */
+ private static void exit() {
+ System.exit(0);
+ }
+
+ /**
+ * Displays this tool's help message on the standard output.
+ */
+ private static void displayHelpMessage() {
+ System.out.println("usage: layoutopt <directories/files to analyze>");
+ }
+
+ /**
+ * Builds a valid Parameters object. Parses the paramters if necessary
+ * and checks for errors.
+ *
+ * @param args The parameters passed from the CLI.
+ */
+ private static Parameters checkParameters(String[] args) {
+ Parameters p = new Parameters();
+
+ if (args.length < 1) {
+ p.valid = false;
+ } else {
+ List<File> files = new ArrayList<File>();
+ for (String path : args) {
+ File file = new File(path);
+ if (file.exists()) {
+ files.add(file);
+ }
+ }
+ p.files = files.toArray(new File[files.size()]);
+ p.valid = true;
+ }
+
+ return p;
+ }
+
+ /**
+ * Parameters parsed from the CLI.
+ */
+ private static class Parameters {
+ /**
+ * True if this list of parameters is valid, false otherwise.
+ */
+ boolean valid;
+
+ /**
+ * Paths (absolute or relative) to the files to be analyzed.
+ */
+ File[] files;
+ }
+}