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 /templates/activities/BlankActivity/root/src/app_package | |
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
Diffstat (limited to 'templates/activities/BlankActivity/root/src/app_package')
5 files changed, 38 insertions, 1 deletions
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 |