@@ -0,0 +1,3401 @@
+// Copyright 2011 Google Inc. All Rights Reserved.%0A//%0A// Licensed under the Apache License, Version 2.0 (the %22License%22);%0A// you may not use this file except in compliance with the License.%0A// You may obtain a copy of the License at%0A//%0A//     http://www.apache.org/licenses/LICENSE-2.0%0A//%0A// Unless required by applicable law or agreed to in writing, software%0A// distributed under the License is distributed on an %22AS IS%22 BASIS,%0A// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A// See the License for the specific language governing permissions and%0A// limitations under the License.%0A%0Apackage com.google.android.apps.analytics.easytracking;%0A%0Aimport android.os.Bundle;%0Aimport android.preference.PreferenceActivity;%0A%0A/**%0A * Extend this class instead of Activity to enable Google Analytics Tracking for%0A * an Activity.  Note that for accurate application-level tracking,%0A * %3Cemph%3Eall%3C/emph%3E Activities in an application must either extend one of the%0A * TrackedActivity classes (i.e. TrackedActivity, TrackedListActivity) or%0A * implement the calls found in this class.  This is necessary as the%0A * EasyTracking library maintains a count of active Activities in order to%0A * determine when a session starts and ends and relies on the fact that a new%0A * Activity's onStart method is called before the old Activity's onStop method%0A * is called.%0A *%0A * The one exception to this flow is when an Activity is being restarted because%0A * of a configuration change (i.e. orientation change) where the%0A * onRetainNonConfigurationInstance method is called after the Activity's onStop%0A * method is called and before the new Activity's onStart is called.%0A * %0A * See the file ReadMe.txt for details on setting up tracking using the%0A * EasyTracker library.%0A */%0Apublic class TrackedPreferenceActivity extends PreferenceActivity %7B%0A  @Override%0A  protected void onCreate(Bundle savedInstanceState) %7B%0A      super.onCreate(savedInstanceState);%0A      %0A      // Only one call to setContext is needed, but additional calls don't hurt%0A      // anything, so we'll always make the call to ensure EasyTracker gets%0A      // setup properly.%0A      EasyTracker.getTracker().setContext(this);%0A  %7D%0A%0A  @Override%0A  protected void onStart() %7B%0A    super.onStart();%0A    %0A    // This call will ensure that the Activity in question is tracked properly,%0A    // based on the setting of ga_auto_activity_tracking parameter.  It will%0A    // also ensure that startNewSession is called appropriately.%0A    EasyTracker.getTracker().trackActivityStart(this);%0A  %7D%0A%0A  /**%0A   * This method is deprecated in Android 3.0 (Honeycomb) and later, but%0A   * GoogleAnalytics support goes back to Android 1.5 and therefore cannot use%0A   * the Fragment API.%0A   */%0A  @Override%0A  public Object onRetainNonConfigurationInstance() %7B%0A    Object o = super.onRetainNonConfigurationInstance();%0A    %0A    // This call is needed to ensure that configuration changes (like%0A    // orientation) don't result in new sessions.  Remove this line if you want%0A    // configuration changes to for a new session in Google Analytics.%0A    EasyTracker.getTracker().trackActivityRetainNonConfigurationInstance();%0A    return o;%0A  %7D%0A%0A  @Override%0A  protected void onStop() %7B%0A    super.onStop();%0A    %0A    // This call is needed to ensure time spent in an Activity and an%0A    // Application are measured accurately.%0A    EasyTracker.getTracker().trackActivityStop(this);%0A  %7D%0A%7D

Enable tracking for PreferencesActivity