public class

CarouselFragment

extends Fragment
java.lang.Object
   ↳ android.app.Fragment
     ↳ com.htc.fragment.widget.CarouselFragment

Class Overview

A fragment that contains and runs multiple embedded fragments or views. For having a tab with edit mode, the things you must do are as the following:

  • Please have your host fragment extend CarouselFragment. When you implement the constructor of your fragment, a call to super() with the authority of your database which contains the information of every element of your tab as the parameter is required. Also, for supporting nested tabs, a group ID is required for your fragment in its constructor. A change to the prototype of CarouselHost.addTab() is done for more elegant way of function call. Please refer to the following example for all the important notices mentioned above:
              public class DemoCarousel extends CarouselFragment {
                  public DemoCarousel() {
                      super(MyProvider.AUTHORITY);
                      setGId(0);
                  }
                  
                  public void onActivityCreated(Bundle savedInstanceState) {
                      super.onActivityCreated(savedInstanceState);
                      
                      CarouselHost host = getCarouselHost();
    
                      Context tabContext = getActivity();
    
                      host.addTab(tabContext, new CarouselTabSpec("Tab1",
                          R.string.tab1,
                          R.drawable.common_icon_artist_rest ,
                          R.drawable.common_icon_artist_on,
                          R.drawable.common_icon_overlay_artist,
                          "com.htc.fragment.app.Tab1"));
    
                      host.setCountVisibility("Tab1", true);
                      host.setCountText("Tab1", "12");
    
                      host.addTab(tabContext, new CarouselTabSpec("Tab2",
                          R.string.tab2,
                          R.drawable.common_icon_albums_rest ,
                          R.drawable.common_icon_albums_on,
                          R.drawable.common_icon_overlay_album,
                          "com.htc.fragment.app",
                          "com.htc.fragment.app.Tab2"));
                      ...
                      
                  }
              }
        
  • Implement your own provider which extends CarouselProvider for saving information of each of your tab element. Sample code is as the following:
             public class MyProvider extends CarouselProvider {
                 public static final String AUTHORITY = "com.htc.fragment.app.MyProvider";
                 public MyProvider(){
                     super();
                     setupCarousel(AUTHORITY);
                 }
             }
        
  • In your Manifest file, please add information for your provider. For example:
              
        

Summary

Nested Classes
interface CarouselFragment.EditModeListener  
Constants
int FEATURE_CUSTOM_TITLE
int FEATURE_NO_EDITOR
[Expand]
Inherited Constants
From interface android.content.ComponentCallbacks2
Public Constructors
CarouselFragment(String authority)
Constructor
Public Methods
CarouselHost getCarouselHost()
Returns the CarouselHost the activity is using to host its tabs.
CarouselWidget getCarouselWidget()
Returns the CarouselWidget the activity is using to draw the actual tabs.
void onConfigurationChanged(Configuration newConfig)
void onCreate(Bundle savedInstanceState)
View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle saved)
void onCurrentTabChanged(String currentTab)
Callback function when the current tab is changed
void onDestroy()
void onDestroyView()
void onPause()
void onResume()
void onSaveInstanceState(Bundle outState)
void onStart()
void onTabEndSliding(String endTag)
A callback function for knowing when the user ends the drag motion
void onTabStartSliding(String startTag)
A callback function for knowing when the user starts to drag the tab selector
final boolean requestCarouselFeature(int featureId)
Enables extended screen features.
void setDefaultTab(String tag)
Sets the default tab that is the first tab highlighted.
void setDefaultTab(int index)
Sets the default tab that is the first tab highlighted.
void setEditModeListener(CarouselFragment.EditModeListener listener)
void setGId(int gId)
When there are several carousels in your application, you need to assign each carousel to an unique id.
void setGId(String gId)
When there are several carousels in your application, you need to assign each carousel to an unique id.
void setOnTabChangedListener(CarouselHost.OnTabChangeListener l)
Registers a callback to be invoked when the selected state of any of the items in this list changes
Protected Methods
void enterEditMode()
void exitEditMode()
[Expand]
Inherited Methods
From class android.app.Fragment
From class java.lang.Object
From interface android.content.ComponentCallbacks
From interface android.content.ComponentCallbacks2
From interface android.view.View.OnCreateContextMenuListener

Constants

public static final int FEATURE_CUSTOM_TITLE

Since: API Level 4.4

Constant Value: 4 (0x00000004)

public static final int FEATURE_NO_EDITOR

Since: API Level 4.4

Constant Value: 8 (0x00000008)

Public Constructors

public CarouselFragment (String authority)

Since: API Level 4.0

Constructor

Parameters
authority The authority of your database which is used to maintain the information of every element of your tab

Public Methods

public CarouselHost getCarouselHost ()

Since: API Level 4.0

Returns the CarouselHost the activity is using to host its tabs.

Returns

public CarouselWidget getCarouselWidget ()

Since: API Level 4.0

Returns the CarouselWidget the activity is using to draw the actual tabs.

Returns

public void onConfigurationChanged (Configuration newConfig)

Since: API Level

public void onCreate (Bundle savedInstanceState)

Since: API Level

public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle saved)

Since: API Level

public void onCurrentTabChanged (String currentTab)

Since: API Level 4.0

Callback function when the current tab is changed

Parameters
currentTab The tag of the current tab

public void onDestroy ()

Since: API Level

public void onDestroyView ()

Since: API Level

public void onPause ()

Since: API Level

public void onResume ()

Since: API Level

public void onSaveInstanceState (Bundle outState)

Since: API Level

public void onStart ()

Since: API Level

public void onTabEndSliding (String endTag)

Since: API Level 4.0

A callback function for knowing when the user ends the drag motion

Parameters
endTag The tag of the tab which the user end up dragging the tab indicator

public void onTabStartSliding (String startTag)

Since: API Level 4.0

A callback function for knowing when the user starts to drag the tab selector

Parameters
startTag The tag of tab which the users start the dragging

public final boolean requestCarouselFeature (int featureId)

Since: API Level 4.0

Enables extended screen features. This must be called before setContentView(). May be called as many times as desired as long as it is before setContentView(). If not called, no extended features will be available. You can not turn off a feature once it is requested. You canot use other title features with FEATURE_CUSTOM_TITLE.

Parameters
featureId The desired features, defined as constants by Window.
Returns
  • The features that are now set.

public void setDefaultTab (String tag)

Since: API Level 4.0

Sets the default tab that is the first tab highlighted.

Parameters
tag The name of the default tab

public void setDefaultTab (int index)

Since: API Level 4.0

Sets the default tab that is the first tab highlighted.

Parameters
index The index of the default tab

public void setEditModeListener (CarouselFragment.EditModeListener listener)

Since: API Level 4.0

public void setGId (int gId)

Since: API Level 4.0

When there are several carousels in your application, you need to assign each carousel to an unique id.

Parameters
gId Should be unique

public void setGId (String gId)

Since: API Level 4.0

When there are several carousels in your application, you need to assign each carousel to an unique id.

Parameters
gId Should be unique

public void setOnTabChangedListener (CarouselHost.OnTabChangeListener l)

Since: API Level 4.0

Registers a callback to be invoked when the selected state of any of the items in this list changes

Parameters
l The callback that will run

Protected Methods

protected void enterEditMode ()

Since: API Level 4.0

protected void exitEditMode ()

Since: API Level 4.0