[Java]
Package com. umeng. example. analytics;
Import java. util. HashMap;
Import android. app. Activity;
Import android. content. Context;
Import android. OS. Bundle;
Import android. support. v4.app. Fragment;
Import android. view. LayoutInflater;
Import android. view. View;
Import android. view. ViewGroup;
Import android. widget. Button;
Import android. widget. Toast;
Import com. umeng. analytics. MobclickAgent;
Import com. umeng. example. R;
Import com. umeng. ui. BaseSinglePaneActivity;
Public class AnalyticsHome extends BaseSinglePaneActivity {
Private Context mContext;
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
MContext = this;
MobclickAgent. setDebugMode (true );
// MobclickAgent. setAutoLocation (false );
// MobclickAgent. setSessionContinueMillis (10000 );
// MobclickAgent. setUpdateOnlyWifi (false );
MobclickAgent. onError (this );
MobclickAgent. updateOnlineConfig (this );
}
@ Override
Public void onResume (){
Super. onResume ();
MobclickAgent. onResume (mContext );
}
@ Override
Public void onPause (){
Super. onPause ();
MobclickAgent. onPause (mContext );
}
@ Override
Protected Fragment onCreatePane (){
Return new AnalyticsHomeDashboardFragment ();
}
Public static class AnalyticsHomeDashboardFragment extends Fragment {
Context mContext;
Private Button online_config;
Private Button event;
Private Button kv_event;
Private Button event_begin;
Private Button event_end;
Private Button event_duration;
Private View. OnClickListener listener = new View. OnClickListener (){
Public void onClick (View v ){
// TODO Auto-generated method stub
Int id = v. getId ();
If (id = R. id. umeng_example_analytics_online_config ){
String onlineParams = MobclickAgent. getConfigParams (
MContext, "abc"); // the demo param's key is 'abc'
If (onlineParams. equals ("")){
Toast. makeText (mContext, "Get No Online Params ",
Toast. LENGTH_SHORT). show ();
} Else
Toast. makeText (mContext,
"Online Params:" + onlineParams,
Toast. LENGTH_SHORT). show ();
} Else if (id = R. id. umeng_example_analytics_event ){
MobclickAgent. onEvent (mContext, "click ");
MobclickAgent. onEvent (mContext, "click", "button ");
} Else if (id = R. id. umeng_example_analytics_ekv ){
HashMap <String, String> map = new HashMap <String, String> ();
Map. put ("type", "popular ");
Map. put ("artist", "JJLin ");
MobclickAgent. onEvent (mContext, "music", map );
} Else if (id = R. id. umeng_example_analytics_duration ){
// We need manual to compute the Events duration
MobclickAgent. onEventDuration (mContext, "book", 12000 );
MobclickAgent. onEventDuration (mContext, "book", "chapter1 ",
23000 );
HashMap <String, String> map = new HashMap <String, String> ();
Map. put ("type", "popular ");
Map. put ("artist", "JJLin ");
MobclickAgent. onEventDuration (mContext, "music", map,
2330000 );
} Else if (id = R. id. umeng_example_analytics_event_begin ){
// Log. I ("duration", "start ");
// When the events start
MobclickAgent. onEventBegin (mContext, "music ");
MobclickAgent. onEventBegin (mContext, "music", "one ");
HashMap <String, String> map = new HashMap <String, String> ();
Map. put ("type", "popular ");
Map. put ("artist", "JJLin ");
MobclickAgent. onKVEventBegin (mContext, "music", map,
"Flag0 ");
} Else if (id = R. id. umeng_example_analytics_event_end ){
// Log. I ("duration", "end ");
// When the event end
MobclickAgent. onEventEnd (mContext, "music ");
MobclickAgent. onEventEnd (mContext, "music", "one ");
MobclickAgent. onKVEventEnd (mContext, "music", "flag0 ");
}
}
};
@ Override
Public void onAttach (Activity activity ){
Super. onAttach (activity );
MContext = activity;
}
@ Override
Public View onCreateView (LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState ){
View root = inflater. inflate (R. layout. umeng_example_analytics,
Container, false );
FindViews (root );
Return root;
}
Private void findViews (View root ){
Online_config = (Button) root
. FindViewById (R. id. umeng_example_analytics_online_config );
Event = (Button) root
. FindViewById (R. id. umeng_example_analytics_event );
Kv_event = (Button) root
. FindViewById (R. id. umeng_example_analytics_ekv );
Event_begin = (Button) root
. FindViewById (R. id. umeng_example_analytics_event_begin );
Event_end = (Button) root
. FindViewById (R. id. umeng_example_analytics_event_end );
Event_duration = (Button) root www.2cto.com
. FindViewById (R. id. umeng_example_analytics_duration );
Online_config.setOnClickListener (listener );
Event. setOnClickListener (listener );
Kv_event.setOnClickListener (listener );
Event_begin.setOnClickListener (listener );
Event_end.setOnClickListener (listener );
Event_duration.setOnClickListener (listener );
}
}
}
Author: manoel