diff options
author | Tor Norbye <tnorbye@google.com> | 2012-06-13 20:15:13 -0700 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2012-06-14 11:40:51 -0700 |
commit | 5978cd057931af1e98ecc51d4bc29b79dc147da2 (patch) | |
tree | 708664155556f0ec3b647eb18fa41e77e090aff1 | |
parent | f4f17275b1fe8644073e3ef485ca12291125ae83 (diff) | |
download | sdk-5978cd057931af1e98ecc51d4bc29b79dc147da2.zip sdk-5978cd057931af1e98ecc51d4bc29b79dc147da2.tar.gz sdk-5978cd057931af1e98ecc51d4bc29b79dc147da2.tar.bz2 |
Update templates
This changeset updates the activity templates with new versions
from Roman. Also fixes a couple of bugs he ran into: the
camel case to underscore conversion methods were reversed, and
the template test wizard didn't reset the activity template
once the second page was shown.
Change-Id: I353af646f92f37bf2a9827d0dc68a409dd9358bc
22 files changed, 116 insertions, 27 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/FmCamelCaseToUnderscoreMethod.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/FmCamelCaseToUnderscoreMethod.java index f017aa7..b855765 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/FmCamelCaseToUnderscoreMethod.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/FmCamelCaseToUnderscoreMethod.java @@ -33,6 +33,6 @@ public class FmCamelCaseToUnderscoreMethod implements TemplateMethodModel { if (args.size() != 1) { throw new TemplateModelException("Wrong arguments"); } - return new SimpleScalar(AdtUtils.underlinesToCamelCase(args.get(0).toString())); + return new SimpleScalar(AdtUtils.camelCaseToUnderlines(args.get(0).toString())); } }
\ No newline at end of file diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/FmUnderscoreToCamelCaseMethod.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/FmUnderscoreToCamelCaseMethod.java index 94a41da..26d4fad 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/FmUnderscoreToCamelCaseMethod.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/FmUnderscoreToCamelCaseMethod.java @@ -34,6 +34,6 @@ public class FmUnderscoreToCamelCaseMethod implements TemplateMethodModel { if (args.size() != 1) { throw new TemplateModelException("Wrong arguments"); } - return new SimpleScalar(AdtUtils.camelCaseToUnderlines(args.get(0).toString())); + return new SimpleScalar(AdtUtils.underlinesToCamelCase(args.get(0).toString())); } }
\ No newline at end of file diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/TemplateTestPage.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/TemplateTestPage.java index 90aa28a..e461d55 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/TemplateTestPage.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/TemplateTestPage.java @@ -147,8 +147,6 @@ public class TemplateTestPage extends WizardPage validatePage(); } - - File getLocation() { return mTemplate; } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/TemplateTestWizard.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/TemplateTestWizard.java index bca50c6..b3b1ef2 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/TemplateTestWizard.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/TemplateTestWizard.java @@ -65,6 +65,8 @@ public class TemplateTestWizard extends NewTemplateWizard { mMainPage = new NewTemplatePage(mValues, true); addPage(mMainPage); + } else { + mValues.setTemplateLocation(file); } return mMainPage; diff --git a/templates/activities/BlankActivity/recipe.xml.ftl b/templates/activities/BlankActivity/recipe.xml.ftl index 2ce72db..97b9ba7 100644 --- a/templates/activities/BlankActivity/recipe.xml.ftl +++ b/templates/activities/BlankActivity/recipe.xml.ftl @@ -13,11 +13,10 @@ <merge from="res/values-large/dimens.xml" /> <merge from="res/values/strings.xml.ftl" /> - <!-- Decide whether or not to add the support library --> - <#if navType != "none"> - <copy from="${android.templatesRes}/android-support-v4.jar.bin" - to="libs/android-support-v4.jar" /> - </#if> + <!-- Always include the support library because we use NavUtils, ViewPager, etc. --> + <!-- TODO: automatically overwrite only if the version is newer, otherwise silently fail --> + <copy from="${android.templatesRes}/android-support-v4.jar.bin" + to="libs/android-support-v4.jar" /> <!-- Decide what kind of layout to add (viewpager or not) --> <#if navType?contains("pager")> diff --git a/templates/activities/BlankActivity/root/AndroidManifest.xml.ftl b/templates/activities/BlankActivity/root/AndroidManifest.xml.ftl index ffcce79..ec20836 100644 --- a/templates/activities/BlankActivity/root/AndroidManifest.xml.ftl +++ b/templates/activities/BlankActivity/root/AndroidManifest.xml.ftl @@ -1,15 +1,18 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" > <application> - <activity android:name=".${activityClass}" - android:label="@string/activity_name"> - <intent-filter android:label="@string/activity_name"> + android:label="@string/title_${activityToLayout(activityClass)}"> + <#if parentActivityClass != ""> + <meta-data android:name="android.support.PARENT_ACTIVITY" + android:value="${parentActivityClass}" /> + <#else> + <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> + </#if> </activity> - </application> </manifest> diff --git a/templates/activities/BlankActivity/root/res/values/strings.xml.ftl b/templates/activities/BlankActivity/root/res/values/strings.xml.ftl index 753649d..4018308 100644 --- a/templates/activities/BlankActivity/root/res/values/strings.xml.ftl +++ b/templates/activities/BlankActivity/root/res/values/strings.xml.ftl @@ -1,5 +1,5 @@ <resources> - <string name="activity_name">${appTitle}</string> + <string name="title_${activityToLayout(activityClass)}">${activityTitle}</string> <string name="menu_settings">Settings</string> diff --git a/templates/activities/BlankActivity/root/src/app_package/DropdownActivity.java.ftl b/templates/activities/BlankActivity/root/src/app_package/DropdownActivity.java.ftl index 98c1a8f..cb2d894 100644 --- a/templates/activities/BlankActivity/root/src/app_package/DropdownActivity.java.ftl +++ b/templates/activities/BlankActivity/root/src/app_package/DropdownActivity.java.ftl @@ -7,9 +7,11 @@ import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; +import android.support.v4.app.NavUtils; import android.view.Gravity; import android.view.LayoutInflater; import android.view.Menu; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; @@ -22,6 +24,9 @@ public class ${activityClass} extends FragmentActivity implements ActionBar.OnNa public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.${layoutName}); + <#if parentActivityClass != ""> + getActionBar().setDisplayHomeAsUpEnabled(true); + </#if> // Set up the action bar. final ActionBar actionBar = getActionBar(); @@ -62,6 +67,7 @@ public class ${activityClass} extends FragmentActivity implements ActionBar.OnNa getMenuInflater().inflate(R.menu.${menuName}, menu); return true; } + <#include "_onOptionsItemSelected.java.ftl"> @Override public boolean onNavigationItemSelected(int position, long id) { 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 1ebc0fa..eb46d9c 100644 --- a/templates/activities/BlankActivity/root/src/app_package/SimpleActivity.java.ftl +++ b/templates/activities/BlankActivity/root/src/app_package/SimpleActivity.java.ftl @@ -3,12 +3,17 @@ package ${packageName}; import android.os.Bundle; import android.app.Activity; import android.view.Menu; +import android.view.MenuItem; +import android.support.v4.app.NavUtils; public class ${activityClass} extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.${layoutName}); + <#if parentActivityClass != ""> + getActionBar().setDisplayHomeAsUpEnabled(true); + </#if> } @Override @@ -16,4 +21,5 @@ public class ${activityClass} extends Activity { getMenuInflater().inflate(R.menu.${menuName}, menu); return true; } + <#include "_onOptionsItemSelected.java.ftl"> } diff --git a/templates/activities/BlankActivity/root/src/app_package/TabsActivity.java.ftl b/templates/activities/BlankActivity/root/src/app_package/TabsActivity.java.ftl index ab11a7f..0811492 100644 --- a/templates/activities/BlankActivity/root/src/app_package/TabsActivity.java.ftl +++ b/templates/activities/BlankActivity/root/src/app_package/TabsActivity.java.ftl @@ -7,9 +7,11 @@ import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; +import android.support.v4.app.NavUtils; import android.view.Gravity; import android.view.LayoutInflater; import android.view.Menu; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; @@ -21,6 +23,9 @@ public class ${activityClass} extends FragmentActivity implements ActionBar.TabL public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.${layoutName}); + <#if parentActivityClass != ""> + getActionBar().setDisplayHomeAsUpEnabled(true); + </#if> // Set up the action bar. final ActionBar actionBar = getActionBar(); @@ -51,6 +56,7 @@ public class ${activityClass} extends FragmentActivity implements ActionBar.TabL getMenuInflater().inflate(R.menu.${menuName}, menu); return true; } + <#include "_onOptionsItemSelected.java.ftl"> @Override public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { diff --git a/templates/activities/BlankActivity/root/src/app_package/TabsAndPagerActivity.java.ftl b/templates/activities/BlankActivity/root/src/app_package/TabsAndPagerActivity.java.ftl index eb47519..850483f 100644 --- a/templates/activities/BlankActivity/root/src/app_package/TabsAndPagerActivity.java.ftl +++ b/templates/activities/BlankActivity/root/src/app_package/TabsAndPagerActivity.java.ftl @@ -8,10 +8,12 @@ import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; +import android.support.v4.app.NavUtils; import android.support.v4.view.ViewPager; import android.view.Gravity; import android.view.LayoutInflater; import android.view.Menu; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; @@ -34,7 +36,9 @@ public class ${activityClass} extends FragmentActivity<#if navType?contains("tab public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.${layoutName}); - + <#if parentActivityClass != ""> + getActionBar().setDisplayHomeAsUpEnabled(true); + </#if> // Create the adapter that will return a fragment for each of the three primary sections // of the app. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); @@ -78,6 +82,8 @@ public class ${activityClass} extends FragmentActivity<#if navType?contains("tab getMenuInflater().inflate(R.menu.${menuName}, menu); return true; } + <#include "_onOptionsItemSelected.java.ftl"> + <#if navType?contains("tabs")> @Override public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { diff --git a/templates/activities/BlankActivity/root/src/app_package/_onOptionsItemSelected.java.ftl b/templates/activities/BlankActivity/root/src/app_package/_onOptionsItemSelected.java.ftl new file mode 100644 index 0000000..c77fdee --- /dev/null +++ b/templates/activities/BlankActivity/root/src/app_package/_onOptionsItemSelected.java.ftl @@ -0,0 +1,13 @@ + + <#if parentActivityClass != ""> + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + NavUtils.navigateUpFromSameTask(this); + return true; + } + return super.onOptionsItemSelected(item); + } + </#if>
\ No newline at end of file diff --git a/templates/activities/BlankActivity/template.xml b/templates/activities/BlankActivity/template.xml index 10e6bc8..f7fa903 100644 --- a/templates/activities/BlankActivity/template.xml +++ b/templates/activities/BlankActivity/template.xml @@ -37,11 +37,20 @@ </parameter> <parameter - id="appTitle" + id="parentActivityClass" + name="Hierarchical Parent" + type="string" + constraints="activity|exists" + default="" + help="The hierarchical parent activity, used to provide a default implementation for the 'Up' button" /> + + <parameter + id="activityTitle" name="Title" type="string" constraints="nonempty" - default="My Application" + default="MainActivity" + suggest="${activityClass}" help="The name of the activity. For launcher activities, the application title." /> <parameter diff --git a/templates/activities/MasterDetailFlow/root/AndroidManifest.xml.ftl b/templates/activities/MasterDetailFlow/root/AndroidManifest.xml.ftl index 1b9aa76..3f61bbd 100644 --- a/templates/activities/MasterDetailFlow/root/AndroidManifest.xml.ftl +++ b/templates/activities/MasterDetailFlow/root/AndroidManifest.xml.ftl @@ -3,14 +3,22 @@ <application> <activity android:name=".${CollectionName}Activity" android:label="@string/title_${collection_name}"> + <#if parentActivityClass != ""> + <meta-data android:name="android.support.PARENT_ACTIVITY" + android:value="${parentActivityClass}" /> + <#else> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> + </#if> </activity> <activity android:name=".${DetailName}Activity" - android:label="@string/title_${detail_name}" /> + android:label="@string/title_${detail_name}"> + <meta-data android:name="android.support.PARENT_ACTIVITY" + android:value=".${CollectionName}Activity" /> + </activity> </application> </manifest> diff --git a/templates/activities/MasterDetailFlow/root/res/layout/activity_content_detail.xml.ftl b/templates/activities/MasterDetailFlow/root/res/layout/activity_content_detail.xml.ftl index 1d6d5dc..fb7ad72 100755 --- a/templates/activities/MasterDetailFlow/root/res/layout/activity_content_detail.xml.ftl +++ b/templates/activities/MasterDetailFlow/root/res/layout/activity_content_detail.xml.ftl @@ -1,4 +1,6 @@ <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" android:id="@+id/${detail_name}_container" android:layout_width="match_parent" - android:layout_height="match_parent" /> + android:layout_height="match_parent" + tools:context=".${DetailName}Activity" /> diff --git a/templates/activities/MasterDetailFlow/root/res/layout/activity_content_list.xml.ftl b/templates/activities/MasterDetailFlow/root/res/layout/activity_content_list.xml.ftl index 788e763..7f28e72 100644 --- a/templates/activities/MasterDetailFlow/root/res/layout/activity_content_list.xml.ftl +++ b/templates/activities/MasterDetailFlow/root/res/layout/activity_content_list.xml.ftl @@ -1,7 +1,9 @@ <fragment xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" android:name="${packageName}.${CollectionName}Fragment" android:id="@+id/${collection_name}" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="16dp" - android:layout_marginRight="16dp" /> + android:layout_marginRight="16dp" + tools:context=".${CollectionName}Activity" /> diff --git a/templates/activities/MasterDetailFlow/root/res/layout/activity_content_twopane.xml.ftl b/templates/activities/MasterDetailFlow/root/res/layout/activity_content_twopane.xml.ftl index c7a2c75..53b37e6 100644 --- a/templates/activities/MasterDetailFlow/root/res/layout/activity_content_twopane.xml.ftl +++ b/templates/activities/MasterDetailFlow/root/res/layout/activity_content_twopane.xml.ftl @@ -1,11 +1,13 @@ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" android:divider="?android:attr/dividerHorizontal" - android:showDividers="middle"> + android:showDividers="middle" + tools:context=".${CollectionName}Activity"> <fragment android:name="${packageName}.${CollectionName}Fragment" android:id="@+id/${collection_name}" diff --git a/templates/activities/MasterDetailFlow/root/res/layout/fragment_content_detail.xml.ftl b/templates/activities/MasterDetailFlow/root/res/layout/fragment_content_detail.xml.ftl index 9b7ca72..0a51cb7 100644 --- a/templates/activities/MasterDetailFlow/root/res/layout/fragment_content_detail.xml.ftl +++ b/templates/activities/MasterDetailFlow/root/res/layout/fragment_content_detail.xml.ftl @@ -1,6 +1,8 @@ <TextView xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" style="?android:attr/textAppearanceLarge" android:id="@+id/${detail_name}" android:layout_width="match_parent" android:layout_height="match_parent" - android:padding="16dp" /> + android:padding="16dp" + tools:context=".${DetailName}Fragment" /> diff --git a/templates/activities/MasterDetailFlow/root/res/values/strings.xml.ftl b/templates/activities/MasterDetailFlow/root/res/values/strings.xml.ftl index 9b92c7d..4f8aeca 100644 --- a/templates/activities/MasterDetailFlow/root/res/values/strings.xml.ftl +++ b/templates/activities/MasterDetailFlow/root/res/values/strings.xml.ftl @@ -1,5 +1,4 @@ <resources> - <string name="app_name">My ${objectKindPlural} Application</string> <string name="title_${collection_name}">${objectKindPlural}</string> <string name="title_${detail_name}">${objectKind} Detail</string> </resources> diff --git a/templates/activities/MasterDetailFlow/root/src/app_package/ContentDetailActivity.java.ftl b/templates/activities/MasterDetailFlow/root/src/app_package/ContentDetailActivity.java.ftl index a7deaf6..59a90e2 100644 --- a/templates/activities/MasterDetailFlow/root/src/app_package/ContentDetailActivity.java.ftl +++ b/templates/activities/MasterDetailFlow/root/src/app_package/ContentDetailActivity.java.ftl @@ -1,7 +1,7 @@ package ${packageName}; -import android.os.Bundle; import android.content.Intent; +import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.support.v4.app.NavUtils; import android.view.MenuItem; diff --git a/templates/activities/MasterDetailFlow/root/src/app_package/ContentListActivity.java.ftl b/templates/activities/MasterDetailFlow/root/src/app_package/ContentListActivity.java.ftl index 4bc5216..d75c5c3 100644 --- a/templates/activities/MasterDetailFlow/root/src/app_package/ContentListActivity.java.ftl +++ b/templates/activities/MasterDetailFlow/root/src/app_package/ContentListActivity.java.ftl @@ -3,6 +3,8 @@ package ${packageName}; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.FragmentActivity; +import android.support.v4.app.NavUtils; +import android.view.MenuItem; public class ${CollectionName}Activity extends FragmentActivity implements ${CollectionName}Fragment.Callbacks { @@ -12,6 +14,9 @@ public class ${CollectionName}Activity extends FragmentActivity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_${collection_name}); + <#if parentActivityClass != ""> + getActionBar().setDisplayHomeAsUpEnabled(true); + </#if> if (findViewById(R.id.${detail_name}_container) != null) { mTwoPane = true; @@ -20,6 +25,18 @@ public class ${CollectionName}Activity extends FragmentActivity .setActivateOnItemClick(true); } } + <#if parentActivityClass != ""> + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + NavUtils.navigateUpFromSameTask(this); + return true; + } + return super.onOptionsItemSelected(item); + } + </#if> @Override public void onItemSelected(String id) { diff --git a/templates/activities/MasterDetailFlow/template.xml b/templates/activities/MasterDetailFlow/template.xml index 0eed682..d67fb65 100644 --- a/templates/activities/MasterDetailFlow/template.xml +++ b/templates/activities/MasterDetailFlow/template.xml @@ -26,11 +26,20 @@ help="Other examples are 'People', 'Books', etc." /> <parameter - id="appTitle" - name="Application title" + id="parentActivityClass" + name="Hierarchical Parent" + type="string" + constraints="activity|exists" + default="" + help="The hierarchical parent activity, used to provide a default implementation for the 'Up' button" /> + + <parameter + id="activityTitle" + name="Title" type="string" constraints="nonempty" - default="My Application" /> + suggest="${objectKindPlural}" + default="Items" /> <parameter id="packageName" |