aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2012-07-02 08:46:27 -0700
committerandroid code review <noreply-gerritcodereview@google.com>2012-07-02 08:46:28 -0700
commit4c6c45a81807c33cd52bf6782e52a676a2ac940a (patch)
treeb805e0cd92757e26f0b6166178c9e8ddcb086830
parentf931cc8aa188ad22fcc0c675b35620402527b59c (diff)
parente9db0a86e766f52a9cef38f7ad05a32185f0f953 (diff)
downloadsdk-4c6c45a81807c33cd52bf6782e52a676a2ac940a.zip
sdk-4c6c45a81807c33cd52bf6782e52a676a2ac940a.tar.gz
sdk-4c6c45a81807c33cd52bf6782e52a676a2ac940a.tar.bz2
Merge "Project template tweaks"
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/ApplicationInfoPage.java12
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewProjectPage.java26
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewTemplateWizardState.java8
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/Parameter.java47
-rw-r--r--templates/activities/BlankActivity/recipe.xml.ftl2
-rw-r--r--templates/activities/BlankActivity/root/res/layout/activity_simple.xml.ftl1
-rw-r--r--templates/activities/BlankActivity/root/res/values-large/dimens.xml5
-rw-r--r--templates/activities/BlankActivity/root/res/values/dimens.xml5
-rw-r--r--templates/activities/BlankActivity/root/src/app_package/SimpleActivity.java.ftl4
-rw-r--r--templates/activities/BlankActivity/template.xml4
-rw-r--r--templates/activities/MasterDetailFlow/template.xml2
-rw-r--r--templates/other/BroadcastReceiver/template.xml2
-rw-r--r--templates/other/ContentProvider/template.xml2
-rw-r--r--templates/other/CustomView/template.xml2
-rw-r--r--templates/other/Service/template.xml2
-rwxr-xr-xtemplates/projects/NewAndroidApplication/root/res/drawable-hdpi/ic_launcher.pngbin4996 -> 9397 bytes
-rwxr-xr-xtemplates/projects/NewAndroidApplication/root/res/drawable-mdpi/ic_launcher.pngbin3065 -> 5237 bytes
-rwxr-xr-xtemplates/projects/NewAndroidApplication/root/res/drawable-xhdpi/ic_launcher.pngbin6679 -> 14383 bytes
18 files changed, 79 insertions, 45 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/ApplicationInfoPage.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/ApplicationInfoPage.java
index cda13b5..4ef2311 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/ApplicationInfoPage.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/ApplicationInfoPage.java
@@ -671,6 +671,18 @@ public class ApplicationInfoPage extends WizardPage implements SelectionListener
return null;
}
+ public static IStatus validateClass(String className) {
+ if (className == null || className.length() == 0) {
+ return new Status(IStatus.ERROR, AdtPlugin.PLUGIN_ID,
+ "Class name must be specified.");
+ }
+ if (className.indexOf('.') != -1) {
+ return new Status(IStatus.ERROR, AdtPlugin.PLUGIN_ID,
+ "Enter just a class name, not a full package name");
+ }
+ return JavaConventions.validateJavaTypeName(className, JDK_15, JDK_15);
+ }
+
private IStatus validateActivity() {
// Validate activity (if creating an activity)
if (!mValues.createActivity) {
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewProjectPage.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewProjectPage.java
index dcb897e..3e4e342 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewProjectPage.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewProjectPage.java
@@ -30,6 +30,9 @@ import com.android.sdklib.AndroidVersion;
import com.android.sdklib.IAndroidTarget;
import com.google.common.collect.Maps;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
@@ -413,9 +416,9 @@ public class NewProjectPage extends WizardPage
try {
mIgnore = true;
if (!mValues.projectModified) {
- mValues.projectName = mValues.applicationName;
- mProjectText.setText(mValues.applicationName);
- updateProjectLocation(mValues.applicationName);
+ mValues.projectName = appNameToProjectName(mValues.applicationName);
+ mProjectText.setText(mValues.projectName);
+ updateProjectLocation(mValues.projectName);
}
updateActivityNames(mValues.applicationName);
} finally {
@@ -429,6 +432,23 @@ public class NewProjectPage extends WizardPage
validatePage();
}
+ private String appNameToProjectName(String appName) {
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ IStatus nameStatus = workspace.validateName(appName, IResource.PROJECT);
+ if (nameStatus.isOK()) {
+ return appName;
+ }
+ StringBuilder sb = new StringBuilder(appName.length());
+ for (int i = 0, n = appName.length(); i < n; i++) {
+ char c = appName.charAt(i);
+ if (Character.isLetterOrDigit(c) || c == '.' || c == '-' || c == ' ') {
+ sb.append(c);
+ }
+ }
+
+ return sb.toString().trim();
+ }
+
/** If the project should be created in the workspace, then update the project location
* based on the project name. */
private void updateProjectLocation(String projectName) {
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewTemplateWizardState.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewTemplateWizardState.java
index 84d2a5d..02bbb10 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewTemplateWizardState.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewTemplateWizardState.java
@@ -125,7 +125,13 @@ public class NewTemplateWizardState {
parameters.put(ATTR_MIN_API_LEVEL, manifest.getMinSdkName());
parameters.put(ATTR_TARGET_API, manifest.getTargetSdkVersion());
IAndroidTarget target = Sdk.getCurrent().getTarget(project);
- parameters.put(NewProjectWizard.ATTR_BUILD_API, target.getVersion().getApiLevel());
+ int buildApi;
+ if (target != null) {
+ buildApi = target.getVersion().getApiLevel();
+ } else {
+ buildApi = manifest.getTargetSdkVersion();
+ }
+ parameters.put(NewProjectWizard.ATTR_BUILD_API, buildApi);
return getTemplateHandler().render(project, parameters);
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/Parameter.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/Parameter.java
index 7436a26..e7429dd 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/Parameter.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/Parameter.java
@@ -97,6 +97,9 @@ class Parameter {
/** The associated value must not be empty */
NONEMPTY,
+ /** The associated value is allowed to be empty */
+ EMPTY,
+
/** The associated value should represent a fully qualified activity class name */
ACTIVITY,
@@ -278,33 +281,35 @@ class Parameter {
mValidator = ResourceNameValidator.create(false, ResourceFolderType.DRAWABLE);
}
return mValidator;
- } else if (constraints.contains(Constraint.CLASS)
+ } else if (constraints.contains(Constraint.PACKAGE)
+ || constraints.contains(Constraint.CLASS)
|| constraints.contains(Constraint.ACTIVITY)) {
mValidator = new IInputValidator() {
@Override
public String isValid(String newText) {
- // Deliberately allow empty strings for parameters that aren't required
- if (newText.trim().isEmpty()
- && !constraints.contains(Constraint.NONEMPTY)) {
- return null;
+ newText = newText.trim();
+ if (newText.isEmpty()) {
+ if (constraints.contains(Constraint.EMPTY)) {
+ return null;
+ } else if (constraints.contains(Constraint.NONEMPTY)) {
+ return String.format("Enter a value for %1$s", name);
+ } else {
+ // Compatibility mode: older templates might not specify;
+ // in that case, accept empty
+ if (!"activityClass".equals(id)) { //$NON-NLS-1$
+ return null;
+ }
+ }
}
-
- // TODO: Don't use *activity* validator if it doesn't have to be one
- // (e.g. is CLASS, not ACTIVITY)
- IStatus status = ApplicationInfoPage.validateActivity(newText.trim());
- if (status != null && !status.isOK()) {
- return status.getMessage();
+ IStatus status;
+ if (constraints.contains(Constraint.ACTIVITY)) {
+ status = ApplicationInfoPage.validateActivity(newText);
+ } else if (constraints.contains(Constraint.PACKAGE)) {
+ status = ApplicationInfoPage.validatePackage(newText);
+ } else {
+ assert constraints.contains(Constraint.CLASS);
+ status = ApplicationInfoPage.validateClass(newText);
}
-
- return null;
- }
- };
- return mValidator;
- } else if (constraints.contains(Constraint.PACKAGE)) {
- mValidator = new IInputValidator() {
- @Override
- public String isValid(String newText) {
- IStatus status = ApplicationInfoPage.validatePackage(newText.trim());
if (status != null && !status.isOK()) {
return status.getMessage();
}
diff --git a/templates/activities/BlankActivity/recipe.xml.ftl b/templates/activities/BlankActivity/recipe.xml.ftl
index 6c0dc6a..05c5d57 100644
--- a/templates/activities/BlankActivity/recipe.xml.ftl
+++ b/templates/activities/BlankActivity/recipe.xml.ftl
@@ -9,8 +9,6 @@
<instantiate from="res/menu/main.xml.ftl"
to="res/menu/${menuName}.xml" />
- <merge from="res/values/dimens.xml" />
- <merge from="res/values-large/dimens.xml" />
<merge from="res/values/strings.xml.ftl" />
<!-- Decide what kind of layout to add (viewpager or not) -->
diff --git a/templates/activities/BlankActivity/root/res/layout/activity_simple.xml.ftl b/templates/activities/BlankActivity/root/res/layout/activity_simple.xml.ftl
index 457c0bf..a472bfe 100644
--- a/templates/activities/BlankActivity/root/res/layout/activity_simple.xml.ftl
+++ b/templates/activities/BlankActivity/root/res/layout/activity_simple.xml.ftl
@@ -8,7 +8,6 @@
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
- android:padding="@dimen/padding_medium"
android:text="@string/hello_world"
tools:context=".${activityClass}" />
diff --git a/templates/activities/BlankActivity/root/res/values-large/dimens.xml b/templates/activities/BlankActivity/root/res/values-large/dimens.xml
deleted file mode 100644
index d8cd7c2..0000000
--- a/templates/activities/BlankActivity/root/res/values-large/dimens.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<resources>
- <dimen name="padding_small">8dp</dimen>
- <dimen name="padding_medium">16dp</dimen>
- <dimen name="padding_large">16dp</dimen>
-</resources>
diff --git a/templates/activities/BlankActivity/root/res/values/dimens.xml b/templates/activities/BlankActivity/root/res/values/dimens.xml
deleted file mode 100644
index d95a70f..0000000
--- a/templates/activities/BlankActivity/root/res/values/dimens.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<resources>
- <dimen name="padding_small">8dp</dimen>
- <dimen name="padding_medium">8dp</dimen>
- <dimen name="padding_large">16dp</dimen>
-</resources>
diff --git a/templates/activities/BlankActivity/root/src/app_package/SimpleActivity.java.ftl b/templates/activities/BlankActivity/root/src/app_package/SimpleActivity.java.ftl
index 70cc3f7..6021829 100644
--- a/templates/activities/BlankActivity/root/src/app_package/SimpleActivity.java.ftl
+++ b/templates/activities/BlankActivity/root/src/app_package/SimpleActivity.java.ftl
@@ -3,8 +3,10 @@ package ${packageName};
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
+<#if parentActivityClass != "">
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
+</#if>
public class ${activityClass} extends Activity {
@@ -22,5 +24,7 @@ public class ${activityClass} extends Activity {
getMenuInflater().inflate(R.menu.${menuName}, menu);
return true;
}
+<#if parentActivityClass != "">
<#include "include_onOptionsItemSelected.java.ftl">
+</#if>
}
diff --git a/templates/activities/BlankActivity/template.xml b/templates/activities/BlankActivity/template.xml
index 00b8fb4..00a91e5 100644
--- a/templates/activities/BlankActivity/template.xml
+++ b/templates/activities/BlankActivity/template.xml
@@ -21,7 +21,7 @@
id="layoutName"
name="Layout Name"
type="string"
- constraints="layout|unique"
+ constraints="layout|unique|nonempty"
suggest="${activityToLayout(activityClass)}"
default="activity_main"
help="The name of the layout to create for the activity" />
@@ -43,7 +43,7 @@
id="parentActivityClass"
name="Hierarchical Parent"
type="string"
- constraints="activity|exists"
+ constraints="activity|exists|empty"
default=""
help="The hierarchical parent activity, used to provide a default implementation for the 'Up' button" />
diff --git a/templates/activities/MasterDetailFlow/template.xml b/templates/activities/MasterDetailFlow/template.xml
index 70a3995..f158d14 100644
--- a/templates/activities/MasterDetailFlow/template.xml
+++ b/templates/activities/MasterDetailFlow/template.xml
@@ -33,7 +33,7 @@
id="parentActivityClass"
name="Hierarchical Parent"
type="string"
- constraints="activity|exists"
+ constraints="activity|exists|empty"
default=""
help="The hierarchical parent activity, used to provide a default implementation for the 'Up' button" />
diff --git a/templates/other/BroadcastReceiver/template.xml b/templates/other/BroadcastReceiver/template.xml
index 09869ff..5a998f2 100644
--- a/templates/other/BroadcastReceiver/template.xml
+++ b/templates/other/BroadcastReceiver/template.xml
@@ -9,7 +9,7 @@
id="className"
name="Class Name"
type="string"
- constraints="class|unique"
+ constraints="class|unique|nonempty"
default="MyReceiver" />
<parameter
diff --git a/templates/other/ContentProvider/template.xml b/templates/other/ContentProvider/template.xml
index c6730d8..32a113a 100644
--- a/templates/other/ContentProvider/template.xml
+++ b/templates/other/ContentProvider/template.xml
@@ -9,7 +9,7 @@
id="className"
name="Class Name"
type="string"
- constraints="class|unique"
+ constraints="class|unique|nonempty"
default="MyContentProvider" />
<parameter
diff --git a/templates/other/CustomView/template.xml b/templates/other/CustomView/template.xml
index 9bd6d98..87a1b2a 100644
--- a/templates/other/CustomView/template.xml
+++ b/templates/other/CustomView/template.xml
@@ -18,7 +18,7 @@
id="viewClass"
name="View Class"
type="string"
- constraints="class|unique"
+ constraints="class|unique|nonempty"
default="MyView"
help="By convention, should end in 'View'" />
diff --git a/templates/other/Service/template.xml b/templates/other/Service/template.xml
index 3ce6e6a..bd22124 100644
--- a/templates/other/Service/template.xml
+++ b/templates/other/Service/template.xml
@@ -9,7 +9,7 @@
id="className"
name="Class Name"
type="string"
- constraints="class|unique"
+ constraints="class|unique|nonempty"
default="MyService" />
<parameter
diff --git a/templates/projects/NewAndroidApplication/root/res/drawable-hdpi/ic_launcher.png b/templates/projects/NewAndroidApplication/root/res/drawable-hdpi/ic_launcher.png
index fba1ff0..96a442e 100755
--- a/templates/projects/NewAndroidApplication/root/res/drawable-hdpi/ic_launcher.png
+++ b/templates/projects/NewAndroidApplication/root/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/templates/projects/NewAndroidApplication/root/res/drawable-mdpi/ic_launcher.png b/templates/projects/NewAndroidApplication/root/res/drawable-mdpi/ic_launcher.png
index 72a445d..359047d 100755
--- a/templates/projects/NewAndroidApplication/root/res/drawable-mdpi/ic_launcher.png
+++ b/templates/projects/NewAndroidApplication/root/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/templates/projects/NewAndroidApplication/root/res/drawable-xhdpi/ic_launcher.png b/templates/projects/NewAndroidApplication/root/res/drawable-xhdpi/ic_launcher.png
index 002e7b0..71c6d76 100755
--- a/templates/projects/NewAndroidApplication/root/res/drawable-xhdpi/ic_launcher.png
+++ b/templates/projects/NewAndroidApplication/root/res/drawable-xhdpi/ic_launcher.png
Binary files differ