public class

GDActivity

extends Activity
implements ActionBarActivity
java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.view.ContextThemeWrapper
         ↳ android.app.Activity
           ↳ greendroid.app.GDActivity
Known Direct Subclasses

Class Overview

An GDActivity is a regular Activity that hosts an ActionBar. It is extremely simple to use as you have nothing particular to do. Indeed, the ActionBar is automatically added to your own layout when using the getContentView() method. You can also use one of the setActionBarContentView utility methods. As a result, a basic GDActivity will often be initialized using the following snippet of code:

 protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
 
     setActionBarContentView(R.layout.main);
 }
 

An ActionBar is a widget that may contains actions items and a title. You can also set the title putting an extra string with the key GD_ACTION_BAR_TITLE in your Intent:

 Intent intent = new Intent(this, MyGDActivity.class);
 intent.putExtra(ActionBarActivity.GD_ACTION_BAR_TITLE, "Next screen title");
 startActivity(intent);
 

Note: An GDActivity automatically handle the type of the ActionBar (taken from ActionBar.Type) depending on the value returned by the getHomeActivityClass() method. However you can force the type of the action bar in your constructor. Make the Activity declared in the AndroidManifest.xml has at least a constructor with no arguments as required by the Android platform.

 public MyGDActivity() {
     super(ActionBar.Type.Dashboard);
 }
 

All Activities that inherits from an GDActivity are notified when an action button is tapped in the onHandleActionBarItemClick(ActionBarItem, int) method. By default this method does nothing but return false.

Summary

[Expand]
Inherited Constants
From class android.app.Activity
From class android.content.Context
From interface greendroid.app.ActionBarActivity
Public Constructors
GDActivity()

Default constructor.

GDActivity(ActionBar.Type actionBarType)

Create a new Activity with an ActionBar of the given type.

Public Methods
ActionBarItem addActionBarItem(ActionBarItem item)
Add a new item to the ActionBar.
ActionBarItem addActionBarItem(ActionBarItem item, int itemId)
Add a new item to the ActionBar.
ActionBarItem addActionBarItem(ActionBarItem.Type actionBarItemType)
Adds a new item of type type to the ActionBar.
ActionBarItem addActionBarItem(ActionBarItem.Type actionBarItemType, int itemId)
Adds a new item of type type to the ActionBar.
int createLayout()
Returns the identifier of the layout that needs to be created for this ActionBarActivity
ActionBar getActionBar()
Returns the ActionBar.
ActionBar.Type getActionBarType()
The current ActionBar.Type of the hosted ActionBar
FrameLayout getContentView()
Returns the content view.
GDApplication getGDApplication()
A simple utility method that casts the Application returned by Activity.getApplication() into a GDApplication
void onContentChanged()
boolean onHandleActionBarItemClick(ActionBarItem item, int position)
Clients may use this method to listen to ActionBarItems clicks.
void onPostContentChanged()
Called at the end of the onContentChanged() method.
void onPreContentChanged()
Called at the beginning of the onContentChanged() method.
void setActionBarContentView(View view)

Set the activity content to an explicit view.

void setActionBarContentView(View view, ViewGroup.LayoutParams params)

Set the activity content to an explicit view.

void setActionBarContentView(int resID)

Set the activity content from a layout resource.

void setTitle(int titleId)
void setTitle(CharSequence title)
Protected Methods
void ensureLayout()
Call this method to ensure a layout has already been inflated and attached to the top-level View of this Activity.
void onCreate(Bundle savedInstanceState)
void onPostCreate(Bundle savedInstanceState)
void onRestoreInstanceState(Bundle savedInstanceState)
boolean verifyLayout()
Verify the given layout contains everything needed by this Activity.
[Expand]
Inherited Methods
From class android.app.Activity
From class android.view.ContextThemeWrapper
From class android.content.ContextWrapper
From class android.content.Context
From class java.lang.Object
From interface android.content.ComponentCallbacks
From interface android.view.KeyEvent.Callback
From interface android.view.LayoutInflater.Factory
From interface android.view.View.OnCreateContextMenuListener
From interface android.view.Window.Callback
From interface greendroid.app.ActionBarActivity

Public Constructors

public GDActivity ()

Default constructor.

Note: This constructor should never be used manually. In order to instantiate an Activity you should let the Android system do it for you by calling startActivity(Intent)

public GDActivity (ActionBar.Type actionBarType)

Create a new Activity with an ActionBar of the given type.

Note: This constructor should never be used manually. In order to instantiate an Activity you should let the Android system do it for you by calling startActivity(Intent)

Parameters
actionBarType The ActionBar.Type for this Activity

Public Methods

public ActionBarItem addActionBarItem (ActionBarItem item)

Add a new item to the ActionBar.

Parameters
item The item to add to the ActionBar

public ActionBarItem addActionBarItem (ActionBarItem item, int itemId)

Add a new item to the ActionBar.

Parameters
item The item to add to the ActionBar
itemId Unique item ID. Use NONE if you do not need a unique ID.

public ActionBarItem addActionBarItem (ActionBarItem.Type actionBarItemType)

Adds a new item of type type to the ActionBar.

Parameters
actionBarItemType The item to add to the ActionBar

public ActionBarItem addActionBarItem (ActionBarItem.Type actionBarItemType, int itemId)

Adds a new item of type type to the ActionBar.

Parameters
actionBarItemType The item to add to the ActionBar
itemId Unique item ID. Use NONE if you do not need a unique ID.

public int createLayout ()

Returns the identifier of the layout that needs to be created for this ActionBarActivity

Returns
  • The layout identifier of the layout to create

public ActionBar getActionBar ()

Returns the ActionBar. Listening to ActionBar events should be done via the onHandleActionBarItemClick(ActionBarItem, int) method. Most of the time, this method don't need to be used directly.

Returns

public ActionBar.Type getActionBarType ()

The current ActionBar.Type of the hosted ActionBar

Returns

public FrameLayout getContentView ()

Returns the content view. Please note the content view is not the entire view but a FrameLayout that contains everything but the ActionBar.

Returns
  • The content view

public GDApplication getGDApplication ()

A simple utility method that casts the Application returned by Activity.getApplication() into a GDApplication

Returns

public void onContentChanged ()

public boolean onHandleActionBarItemClick (ActionBarItem item, int position)

Clients may use this method to listen to ActionBarItems clicks.

Parameters
item The ActionBarItem that has been clicked
position The position of the clicked item. This number is equal or greater to zero. 0 is the leftmost item.
Returns
  • true if the method has handled the click on the ActionBarItem at position position. Otherwise it returns false.

public void onPostContentChanged ()

Called at the end of the onContentChanged() method. This may be use to initialize the content of the layout (titles, etc.)

public void onPreContentChanged ()

Called at the beginning of the onContentChanged() method. This may be used to initialize all references on elements.

public void setActionBarContentView (View view)

Set the activity content to an explicit view. This view is placed directly into the activity's view hierarchy. It can itself be a complex view hierarchy.

This method is an equivalent to setContentView(View) that automatically wraps the given layout in an ActionBarHost if needed.

Parameters
view The desired content to display.

public void setActionBarContentView (View view, ViewGroup.LayoutParams params)

Set the activity content to an explicit view. This view is placed directly into the activity's view hierarchy. It can itself be a complex view hierarchy.

This method is an equivalent to setContentView(View, LayoutParams) that automatically wraps the given layout in an ActionBarHost if needed.

Parameters
view The desired content to display.
params Layout parameters for the view.

public void setActionBarContentView (int resID)

Set the activity content from a layout resource. The resource will be inflated, adding all top-level views to the activity.

This method is an equivalent to setContentView(int) that automatically wraps the given layout in an ActionBarHost if needed..

Parameters
resID Resource ID to be inflated.

public void setTitle (int titleId)

public void setTitle (CharSequence title)

Protected Methods

protected void ensureLayout ()

Call this method to ensure a layout has already been inflated and attached to the top-level View of this Activity.

protected void onCreate (Bundle savedInstanceState)

protected void onPostCreate (Bundle savedInstanceState)

protected void onRestoreInstanceState (Bundle savedInstanceState)

protected boolean verifyLayout ()

Verify the given layout contains everything needed by this Activity. A GDActivity, for instance, manages an ActionBarHost. As a result this method will return true of the current layout contains such a widget.

Returns
  • true if the current layout fits to the current Activity widgets requirements