/*
 * ************************************************************************
 *
 * ADOBE SYSTEMS INCORPORATED
 * Copyright 2013 Adobe Systems Incorporated
 * All Rights Reserved.
 * NOTICE:  Adobe permits you to use, modify, and distribute this file in accordance with the 
 * terms of the Adobe license agreement accompanying it.  If you have received this file from a 
 * source other than Adobe, then your use, modification, or distribution of it requires the prior 
 * written permission of Adobe.
 *
 **************************************************************************
 */

package com.adobe.primetime.reference.ui.settings;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.AssetManager;
import android.os.Build;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import com.adobe.mediacore.ABRControlParameters;
import com.adobe.mediacore.TextFormat;
import com.adobe.primetime.reference.logging.Logger;
import com.adobe.primetime.reference.PrimetimeReference;
import com.adobe.primetime.reference.R;
import com.adobe.primetime.reference.SplunkHttpServiceConnector;
import com.adobe.primetime.reference.manager.AdsManager;
import com.adobe.primetime.reference.manager.BillingManager;
import com.adobe.primetime.reference.manager.CCManager;
import com.adobe.primetime.reference.manager.DrmManager;
import com.adobe.primetime.reference.manager.InstantOnManager;
import com.adobe.primetime.reference.manager.PlaybackManager;
import com.adobe.primetime.reference.manager.QosManager;
import com.adobe.primetime.reference.manager.VAManager;
import com.adobe.primetime.reference.ui.log.LogActivity;

import java.io.IOException;
import java.lang.reflect.Method;
import java.util.List;

public class SettingsActivity extends PreferenceActivity implements
		PreferenceHolder {
	private final static String LOG_TAG = PrimetimeReference.LOG_APP_NAME
			+ "SettingsActivity";
	private static final String CATALOG_LIST = "content_url_list";
	protected Method mLoadHeaders = null;
	protected Method mHasHeaders = null;

	private List<Header> headers;
	private SharedPreferences prefs;
	private EditTextPreference catalogET, logCountET, remoteLoggingHostET,
			remoteLoggingPortET, remoteLoggingSessionTagET, bufferInitET,
			bufferTimeET;
	private EditTextPreference customAdCuesET, subscribedCuesET;
	private Preference catalogList, logVerbosityList;
	private Preference controlBarCB, ccVisibilityCB, returnHomeCB, forceOMXALCB,
			qosVisbilityCB, seekInAdCB, remoteLoggingActiveCB, toastWarningsCB,
			clickableAdsCB, drmPrecacheCB;

	private Preference advertisingWorkflowEnabledCB,
			advertisingSignalingModeCB, advertisingDelayAdLoadingCB, hasPrerollCB, customAdClientFactoryCB;

	private Preference abrEnabledCB, abrInitialBitrate, abrMinBitrate,abrMaxBitrate, abrMinTrickplayBitrate, abrMaxTrickplayBitrate, abrMaxTrickplayBandwidthusage, abrPolicyLV;

	private Preference revenueOptimizationEnabledCB, revenueOptimizationEndpointUrl, revenueOptimizationAuthString, revenueOptimizationInterval;

	private Preference dvrStartTimeEnabledCB, dvrStartTime,
			dvrSeekingOutsideEnabledCB, dvrSeekingClpEnabledCB,
			dvrSeekingOffset;
	private ListPreference ccFontLV, ccFontColorLV, ccBackgroundColorLV, ccFillColorLV, 
			ccEdgeColorLV, ccSizeLV, ccFontEdgeLV, ccFontOpacityLV,
			ccBackgroundOpacityLV, ccFillOpacityLV;
	private EditTextPreference ccBottomInset, ccSafeArea;

	private Preference instantOnEnabledCB;
	private EditTextPreference instantOnMaxLoad, instantOnConcurrentLoad;

	private EditTextPreference naAppId, naAppName, naAppVersion, naSfcode;
	
	// Video Analytics preferences
	private EditTextPreference
			vaPlayerName, 
			vaPublisher,
			vaChannel,
			vaTrackingServer;

    private Preference
			vaEnableChapterTrackingCB,
			vaEnableUseSslCB,
			vaEnableMetadataBlocksCB,
            vaEnableDebugLoggingCB,
            vaEnableQuietModeCB,
            vaModuleEnabled;

	// Billing metrics preferences
	private SettingsFeature billingPreferences[] = {
			new CustomBooleanSettingsFeature(BillingManager.SETTINGS_BILLING_USE_CUSTOM, BillingManager.DEFAULT_BILLING_USE_CUSTOM, true),
			new BooleanSettingsFeature(BillingManager.SETTINGS_BILLING_ENABLED, BillingManager.DEFAULT_BILLING_ENABLED),
			new StringSettingsFeature(BillingManager.SETTINGS_BILLING_PUBLISHER, BillingManager.DEFAULT_BILLING_PUBLISHER),
			new StringSettingsFeature(BillingManager.SETTINGS_BILLING_REPORT_SUITE, BillingManager.DEFAULT_BILLING_REPORT_SUITE),
			new StringSettingsFeature(BillingManager.SETTINGS_BILLING_VISITOR, BillingManager.DEFAULT_BILLING_VISITOR),
			new StringSettingsFeature(BillingManager.SETTINGS_BILLING_TRACKING_SERVER, BillingManager.DEFAULT_BILLING_TRACKING_SERVER),
			new StringSettingsFeature(BillingManager.SETTINGS_BILLING_STD_DURATION, String.valueOf(BillingManager.DEFAULT_BILLING_STD_DURATION)),
			new StringSettingsFeature(BillingManager.SETTINGS_BILLING_PRO_DURATION, String.valueOf(BillingManager.DEFAULT_BILLING_PRO_DURATION)),
			new StringSettingsFeature(BillingManager.SETTINGS_BILLING_LIVE_DURATION, String.valueOf(BillingManager.DEFAULT_BILLING_LIVE_DURATION))
	};


	private static Activity parent;
	private static boolean preferenceChanged;

	@TargetApi(Build.VERSION_CODES.HONEYCOMB)
	@SuppressWarnings("deprecation")
	@Override
	public void onCreate(Bundle aSavedState) {

		if (parent == null)
			parent = this;
		// onBuildHeaders() will be called during super.onCreate()
		try {
			mLoadHeaders = getClass().getMethod("loadHeadersFromResource",
					int.class, List.class);
			mHasHeaders = getClass().getMethod("hasHeaders");
		} catch (NoSuchMethodException e) {
			PrimetimeReference.logger.w(LOG_TAG + "#onCreate",
					"Exception triggered: " + e.getMessage());
		}
		super.onCreate(aSavedState);
		if (isApi11OrAbove()) {
			android.app.ActionBar actionBar = getActionBar();
			actionBar.setDisplayHomeAsUpEnabled(true);
		} else {
			// API level < 11.
			addPreferencesFromResource(R.xml.preference_empty);
			PreferenceScreen root = getPreferenceScreen();
			root.addPreference(inflatePreferenceScreenFromResource(R.xml.preference_catalog));
			root.addPreference(inflatePreferenceScreenFromResource(R.xml.preference_log_count));
			root.addPreference(inflatePreferenceScreenFromResource(R.xml.preference_log_verbosity));
			root.addPreference(inflatePreferenceScreenFromResource(R.xml.preference_ctrl_bar));
			root.addPreference(inflatePreferenceScreenFromResource(R.xml.preference_cc_visibility));
			root.addPreference(inflatePreferenceScreenFromResource(R.xml.preference_return_home));
			root.addPreference(inflatePreferenceScreenFromResource(R.xml.preference_seek_in_ad));
			root.addPreference(inflatePreferenceScreenFromResource(R.xml.preference_omxal));			
			root.addPreference(inflatePreferenceScreenFromResource(R.xml.preference_qos_visibility));
			root.addPreference(inflatePreferenceScreenFromResource(R.xml.preference_abr_controls));
			root.addPreference(inflatePreferenceScreenFromResource(R.xml.preference_buffer));
			root.addPreference(inflatePreferenceScreenFromResource(R.xml.preference_cc_style));
			root.addPreference(inflatePreferenceScreenFromResource(R.xml.preference_remote_logging));
			root.addPreference(inflatePreferenceScreenFromResource(R.xml.preference_toast_warnings));
			root.addPreference(inflatePreferenceScreenFromResource(R.xml.preference_custom_cues));
			root.addPreference(inflatePreferenceScreenFromResource(R.xml.preference_custom_advertising_workflow));
			root.addPreference(inflatePreferenceScreenFromResource(R.xml.preference_clickable_ads));
			root.addPreference(inflatePreferenceScreenFromResource(R.xml.preference_revenue_optimization));
			root.addPreference(inflatePreferenceScreenFromResource(R.xml.preference_dvr_controls));
            root.addPreference(inflatePreferenceScreenFromResource(R.xml.preference_va_config));
			root.addPreference(inflatePreferenceScreenFromResource(R.xml.preference_instant_on));
			root.addPreference(inflatePreferenceScreenFromResource(R.xml.preference_billing_config));
			initialize(this);
		}
	}

	/**
	 * Inflates a {@link android.preference.PreferenceScreen PreferenceScreen}
	 * from the specified resource.
	 * 
	 * @param resId
	 *            The ID of the XML file
	 * @return The preference screen or null on failure.
	 */
	@SuppressWarnings("deprecation")
	private PreferenceScreen inflatePreferenceScreenFromResource(int resId) {
		try {
			Class<PreferenceManager> cls = PreferenceManager.class;
			Method method = cls.getDeclaredMethod("inflateFromResource",
					Context.class, int.class, PreferenceScreen.class);
			return (PreferenceScreen) method.invoke(getPreferenceManager(),
					this, resId, null);
		} catch (Exception e) {
			PrimetimeReference.logger.w(
					LOG_TAG,
					"Could not inflate preference screen from XML: "
							+ e.getMessage());
		}

		return null;
	}

	@Override
	public void onBuildHeaders(List<Header> aTarget) {
		try {
			mLoadHeaders.invoke(this, R.xml.preference_headers, aTarget);
		} catch (Exception e) {
			PrimetimeReference.logger.w(LOG_TAG + "#onBuildHeaders",
					"Exception triggered: " + e.getMessage());
		}

		headers = aTarget;
		prefs = PreferenceManager.getDefaultSharedPreferences(this);
		setPrefSummaries();
	}

	/**
	 * The fragment in charge of a preference screen.
	 */
	@TargetApi(Build.VERSION_CODES.HONEYCOMB)
	public static class PrefsFragment extends PreferenceFragment implements
			PreferenceHolder {
		@Override
		public void onCreate(Bundle aSavedState) {
			super.onCreate(aSavedState);
			Context anAct = getActivity().getApplicationContext();

			// Find XML resource and use as fragment layout.
			int prefResource = anAct.getResources().getIdentifier(
					getArguments().getString("pref-resource"), "xml",
					anAct.getPackageName());
			addPreferencesFromResource(prefResource);

			SettingsActivity activity = (SettingsActivity) getActivity();
			activity.initialize(this);
		}
	}

	public void onDestroy() {
		if (parent == this)
			parent = null;
		super.onDestroy();
	}

	public void onResume() {
		if (parent == this) {
			// Refresh the header summaries.
			preferenceChanged = false;
			invalidateHeaders();
			onContentChanged();
		}
		try {
			// Hide the screen title, since it's duplicated with the
			// PreferenceCategory title.
			View view = getWindow().getDecorView().findViewById(
					android.R.id.title);
			if (view != null) {
				view.setVisibility(View.GONE);
			}
		} catch (Exception e) {
			PrimetimeReference.logger.w(LOG_TAG + "#onResume",
					"Exception triggered: " + e.getMessage());
		}
		super.onResume();
	}

	/**
	 * Set default values for non existing settings.
	 */
	private void setInitialPrefValues() {
		Editor editor = prefs.edit();

		putBooleanPref(editor, PrimetimeReference.SETTINGS_CONTROLBAR_AUTOHIDE,
				PrimetimeReference.DEFAULT_AUTOHIDE_CONTROL_BAR);
		putBooleanPref(editor, PlaybackManager.SETTINGS_FORCE_OMXAL,
				PlaybackManager.DEFAULT_FORCE_OMXAL);
		putBooleanPref(editor, QosManager.SETTINGS_QOS_VISIBILITY,
				QosManager.DEFAULT_QOS_VISIBILITY);

		putBooleanPref(editor, CCManager.SETTINGS_CC_VISIBILITY, CCManager.DEFAULT_CC_VISIBILITY);

		putBooleanPref(editor, PrimetimeReference.SETTINGS_RETURN_HOME_ON_PLAY_COMPLETE,
				PrimetimeReference.DEFAULT_RETURN_HOME_ON_PLAY_COMPLETE);
		putBooleanPref(editor, PrimetimeReference.SETTINGS_TOAST_WARNINGS,
				PrimetimeReference.DEFAULT_TOAST_WARNINGS);
		putBooleanPref(editor, DrmManager.SETTINGS_DRM_PRE_CACHE,
				DrmManager.DEFAULT_DRM_PRECACHE);
		putBooleanPref(editor, AdsManager.SETTINGS_CLICKABLE_ADS,
				AdsManager.DEFAULT_CLICKABLE_ADS);
		putBooleanPref(editor, PlaybackManager.SETTINGS_REVENUE_OPTIMIZATION,
				PlaybackManager.DEFAULT_REVENUE_OPTIMIZATION);
		// putBooleanPref(editor, PMPDemoApp.SETTINGS_DVR_START_TIME_ENABLED,
		// PMPDemoApp.DEFAULT_DVR_START_TIME_ENABLED);
		// if (!prefs.contains(PMPDemoApp.SETTINGS_DVR_START_TIME_ENABLED) &&
		// dvrStartTime != null)
		// dvrStartTime.setText(String.valueOf(PMPDemoApp.DEFAULT_DVR_START_TIME));

		putBooleanPref(editor, AdsManager.SETTINGS_ADVERTISING_WORKFLOW_ENABLED,
				AdsManager.DEFAULT_ADVERTISING_WORKFLOW_ENABLED);
		putStringPref(editor, AdsManager.SETTINGS_ADVERTISING_SIGNALING_MODE,
				AdsManager.DEFAULT_ADVERTISING_SIGNALING_MODE);
		putStringPref(editor, AdsManager.SETTINGS_CUSTOM_AD_CLIENT_FACTORY,
				AdsManager.DEFAULT_CUSTOM_AD_CLIENT_FACTORY);
		putBooleanPref(editor, AdsManager.SETTINGS_DELAY_AD_LOADING,
				AdsManager.DEFAULT_DELAY_AD_LOADING);
		putBooleanPref(editor, AdsManager.SETTINGS_HAS_PREROLL,
				AdsManager.DEFAULT_HAS_PREROLL);

		putStringPref(editor, PlaybackManager.SETTINGS_REVENUE_OPTIMIZATION_AUTHSTRING,
				PlaybackManager.DEFAULT_REVENUE_OPTIMIZATION_AUTHSTRING);
		putStringPref(editor, PlaybackManager.SETTINGS_REVENUE_OPTIMIZATION_ENDPOINT,
				PlaybackManager.DEFAULT_REVENUE_OPTIMIZATION_ENDPOINT);

        putBooleanPref(editor, VAManager.SETTINGS_VA_ENABLED, VAManager.DEFAULT_VA_ENABLED);
        putBooleanPref(editor, VAManager.SETTINGS_VA_DEBUG_LOGGING_ENABLED, VAManager.DEFAULT_VA_DEBUG_LOGGING);
		putBooleanPref(editor, VAManager.SETTINGS_VA_QUITE_MODE, VAManager.DEFAULT_VA_QUITE_MODE);
		putStringPref(editor, VAManager.SETTINGS_VA_TRACKING_SERVER, VAManager.DEFAULT_VA_TRACKING_SERVER);
        putStringPref(editor, VAManager.SETTINGS_VA_PUBLISHER, VAManager.DEFAULT_VA_PUBLISHER);
        putStringPref(editor, VAManager.SETTINGS_VA_CHANNEL, VAManager.DEFAULT_VA_CHANNEL);
		putBooleanPref(editor, VAManager.SETTINGS_VA_USE_SSL_ENABLED, VAManager.DEFAULT_VA_USE_SSL);
		putBooleanPref(editor, VAManager.SETTINGS_VA_METADATA_BLOCKS_ENABLED, VAManager.DEFAULT_VA_METADATA_BLOCKS_ENABLED);
		putStringPref(editor, VAManager.SETTINGS_VA_PLAYER_NAME, VAManager.DEFAULT_VA_PLAYER_NAME);

		for (SettingsFeature sf : billingPreferences)
		{
			sf.setInitialPreferences(prefs);
		}

		putStringPref(editor, PrimetimeReference.SETTINGS_LOG_MAX_ENTRY_COUNT_KEY,
				String.valueOf(PrimetimeReference.DEFAULT_MAX_ENTRY_COUNT));
		if (!prefs.contains(PrimetimeReference.SETTINGS_CONTENT_URL_KEY)
				&& catalogET != null)
			catalogET.setText(getString(R.string.contentUrl));
		putStringPref(editor, PrimetimeReference.SETTINGS_CONTENT_URL_KEY,
				getString(R.string.contentUrl));
		if (!prefs.contains(PlaybackManager.SETTINGS_BUFFER_INIT)
				&& bufferInitET != null)
			bufferInitET.setText(String
					.valueOf(PlaybackManager.DEFAULT_INIT_BUFFER));
		if (!prefs.contains(PlaybackManager.SETTINGS_BUFFER_TIME)
				&& bufferTimeET != null)
			bufferTimeET.setText(String
					.valueOf(PlaybackManager.DEFAULT_BUFFER_TIME));
		putBooleanPref(editor, PrimetimeReference.SETTINGS_REMOTE_LOGGING_ACTIVE,
				PrimetimeReference.DEFAULT_REMOTE_LOGGING_ACTIVE);
		if (!prefs.contains(PrimetimeReference.SETTINGS_REMOTE_LOGGING_HOST)
				&& remoteLoggingHostET != null)
			remoteLoggingHostET.setText(getString(R.string.remoteLoggingHost));
		if (!prefs.contains(PrimetimeReference.SETTINGS_REMOTE_LOGGING_PORT)
				&& remoteLoggingPortET != null)
			remoteLoggingPortET.setText(getString(R.string.remoteLoggingPort));
		if (!prefs.contains(PrimetimeReference.SETTINGS_REMOTE_LOGGING_SESSION_TAG)
				&& remoteLoggingSessionTagET != null)
			remoteLoggingSessionTagET
					.setText(getString(R.string.remoteLoggingSessionTag));

		putBooleanPref(editor, InstantOnManager.SETTINGS_ENABLED, InstantOnManager.DEFAULT_ENABLED);
		if (!prefs.contains(InstantOnManager.SETTINGS_MAX_LOAD) && instantOnMaxLoad != null)
			instantOnMaxLoad.setText(String.valueOf(InstantOnManager.DEFAULT_MAX_LOAD));
		if (!prefs.contains(InstantOnManager.SETTINGS_CONCURRENT_LOAD) && instantOnConcurrentLoad != null)
			instantOnConcurrentLoad.setText(String.valueOf(InstantOnManager.DEFAULT_CONCURRENT_LOAD));

		editor.commit();
	}

	private void putBooleanPref(Editor editor, String key, boolean value) {
		if (!prefs.contains(key))
			editor.putBoolean(key, value);
	}

	private void putStringPref(Editor editor, String key, String value) {
		if (!prefs.contains(key))
			editor.putString(key, value);
	}

	static <T extends Enum<T>> String[] enumToArray(Class<T> cls) {
		try {
			T[] constants = cls.getEnumConstants();
			String[] stringArray = new String[constants.length];
			for (int i = 0; i < constants.length; i++) {
				stringArray[i] = constants[i].toString();
			}

			return stringArray;
		} catch (Exception ex) {
			throw new RuntimeException(ex);
		}
	}

	/**
	 * Updates preferences summaries.
	 */
	private void setPrefSummaries() {
		// Set catalog summary.
		String contentUrl = prefs.getString(PrimetimeReference.SETTINGS_CONTENT_URL_KEY,
				getString(R.string.contentUrl));
		setHeaderSummary(R.id.settingsContentUrlHeader, contentUrl);
		setSummary(catalogET, contentUrl);
		setSummary(catalogList, contentUrl);
		setCatalogListEntries();

        // Set Log Count summary.
		String logCount = prefs.getString(
				PrimetimeReference.SETTINGS_LOG_MAX_ENTRY_COUNT_KEY,
				String.valueOf(PrimetimeReference.DEFAULT_MAX_ENTRY_COUNT));
		setHeaderSummary(R.id.settingsLogItemsCount, logCount);
		setSummary(logCountET, logCount);

		// Set Log Verbosity summary.
		String logVerbosityString = prefs.getString(
				PrimetimeReference.SETTINGS_LOG_VERBOSITY,
				String.valueOf(Logger.Verbosity.INFO.getLevel()));
		String value = "";
		try {
			String[] verbArray = getResources().getStringArray(
					R.array.log_verbosity);
			value = verbArray[Integer.parseInt(logVerbosityString)];
		} catch (Exception e) {
			PrimetimeReference.logger.w(LOG_TAG + "#setPrefSummaries",
					"Exception triggered: " + e.getMessage());
		}
		setHeaderSummary(R.id.settingsLogVerbosity, value);
		setSummary(logVerbosityList, value);
		PrimetimeReference.logger.setVerbosityLevel(LogActivity.getVerbosity(this));

		// Set AutoHideControlBar summary.
		Boolean autoHideControlBar = prefs.getBoolean(
				PrimetimeReference.SETTINGS_CONTROLBAR_AUTOHIDE,
				PrimetimeReference.DEFAULT_AUTOHIDE_CONTROL_BAR);
		setHeaderSummary(R.id.settingsControlBarAutohide,
				booleanToString(autoHideControlBar));

		// Set advertising workflow summary.
		Boolean advertisingWorkflow = prefs.getBoolean(
				AdsManager.SETTINGS_ADVERTISING_WORKFLOW_ENABLED,
				AdsManager.DEFAULT_ADVERTISING_WORKFLOW_ENABLED);
		setHeaderSummary(R.id.settingsCustomAdvertisingWorkflow,
				booleanToString(advertisingWorkflow));
				
		// Set CC visibility summary.
		Boolean ccVisibility = prefs.getBoolean(CCManager.SETTINGS_CC_VISIBILITY, CCManager.DEFAULT_CC_VISIBILITY);
		setHeaderSummary(R.id.settingsClosedCaptionsVisibility, booleanToString(ccVisibility)); 


		// Set ReturnHome summary.
		Boolean returnHome = prefs.getBoolean(
				PrimetimeReference.SETTINGS_RETURN_HOME_ON_PLAY_COMPLETE,
				PrimetimeReference.DEFAULT_RETURN_HOME_ON_PLAY_COMPLETE);
		setHeaderSummary(R.id.settingsReturnHomeOnPlaybackComplete,
				booleanToString(returnHome));

		// Set Force OpenMax AL summary.
		Boolean forceOMXAL = prefs.getBoolean(
				PlaybackManager.SETTINGS_FORCE_OMXAL,
				PlaybackManager.DEFAULT_FORCE_OMXAL);
		setHeaderSummary(R.id.settingsForceOMXAL,
				booleanToString(forceOMXAL));		
		
		// Set seek in ads summary.
		Boolean seekInAd = prefs.getBoolean(AdsManager.SETTINGS_SEEK_IN_AD,
				AdsManager.DEFAULT_SEEK_IN_AD);
		setHeaderSummary(R.id.settingsSeekInAd, booleanToString(seekInAd));

		// Set clickable ads summary.
		Boolean clickAdsVisibility = prefs.getBoolean(
				AdsManager.SETTINGS_CLICKABLE_ADS,
				AdsManager.DEFAULT_CLICKABLE_ADS);
		setHeaderSummary(R.id.settingsClickableAds,
				booleanToString(clickAdsVisibility));

		// Set QoS visibility summary.
		Boolean qosVisibility = prefs.getBoolean(
				QosManager.SETTINGS_QOS_VISIBILITY,
				QosManager.DEFAULT_QOS_VISIBILITY);
		setHeaderSummary(R.id.settingsQosVisibility,
				booleanToString(qosVisibility));

		// Set ToastWarnings visibility summary.
		Boolean toastWarnings = prefs.getBoolean(
				PrimetimeReference.SETTINGS_TOAST_WARNINGS, PrimetimeReference.DEFAULT_TOAST_WARNINGS);
		setHeaderSummary(R.id.settingsToastWarnings,
				booleanToString(toastWarnings));

		// Set DRM Pre-cache summary
		Boolean drmPrecache = prefs.getBoolean(
				DrmManager.SETTINGS_DRM_PRE_CACHE,
				DrmManager.DEFAULT_DRM_PRECACHE);
		setHeaderSummary(R.id.settingsDrmPrecache, booleanToString(drmPrecache));

		// Set ABR Controls summary.
		Boolean abrControls = prefs.getBoolean(
				PlaybackManager.SETTINGS_ABR_CTRL_ENABLED,
				PlaybackManager.DEFAULT_ABR_CTRL_ENABLED);
		setHeaderSummary(R.id.settingsAbrControl, booleanToString(abrControls));
		String initialBitrate = prefs.getString(
				PlaybackManager.SETTINGS_ABR_INITIAL_BITRATE,
				String.valueOf(PlaybackManager.DEFAULT_INIT_BIT_RATE));
		setSummary(abrInitialBitrate, initialBitrate);
		String minBitrate = prefs.getString(
				PlaybackManager.SETTINGS_ABR_MIN_BITRATE,
				String.valueOf(PlaybackManager.DEFAULT_MIN_BIT_RATE));
		setSummary(abrMinBitrate, minBitrate);
		String maxBitrate = prefs.getString(
				PlaybackManager.SETTINGS_ABR_MAX_BITRATE,
				String.valueOf(PlaybackManager.DEFAULT_MAX_BIT_RATE));
		setSummary(abrMaxBitrate, maxBitrate);
		
		String minTrickplayBitrate = prefs.getString(
				PlaybackManager.SETTINGS_ABR_MIN_TRICKPLAY_BITRATE,
				String.valueOf(PlaybackManager.DEFAULT_MIN_TRICKPLAY_BIT_RATE));
		setSummary(abrMinTrickplayBitrate, minTrickplayBitrate);

		String maxTrickplayBitrate = prefs.getString(
				PlaybackManager.SETTINGS_ABR_MAX_TRICKPLAY_BITRATE,
				String.valueOf(PlaybackManager.DEFAULT_MAX_TRICKPLAY_BIT_RATE));
		setSummary(abrMaxTrickplayBitrate, maxTrickplayBitrate);

		String maxTrickplayBandwidthusage = prefs.getString(
				PlaybackManager.SETTINGS_ABR_MAX_TRICKPLAY_BANDWIDTHUSAGE,
				String.valueOf(PlaybackManager.DEFAULT_MAX_TRICKPLAY_BANDWIDTH_USAGE));
		setSummary(abrMaxTrickplayBandwidthusage, maxTrickplayBandwidthusage);  

		// Set ads logging summary
		Boolean revenueOptimization = prefs.getBoolean(
				PlaybackManager.SETTINGS_REVENUE_OPTIMIZATION,
				PlaybackManager.DEFAULT_REVENUE_OPTIMIZATION);
		setHeaderSummary(R.id.settingsRevenueOptimization, booleanToString(revenueOptimization));
		String endpointUrl = prefs.getString(
				PlaybackManager.SETTINGS_REVENUE_OPTIMIZATION_ENDPOINT,
				PlaybackManager.DEFAULT_REVENUE_OPTIMIZATION_ENDPOINT);
		setSummary(revenueOptimizationEndpointUrl, endpointUrl);
		String authString = prefs.getString(
				PlaybackManager.SETTINGS_REVENUE_OPTIMIZATION_AUTHSTRING,
				PlaybackManager.DEFAULT_REVENUE_OPTIMIZATION_AUTHSTRING);
		setSummary(revenueOptimizationAuthString, authString);
		String batchInterval = prefs.getString(
				PlaybackManager.SETTINGS_REVENUE_OPTIMIZATION_INTERVAL,
				String.valueOf(PlaybackManager.DEFAULT_REVENUE_OPTIMIZATION_INTERVAL));
		setSummary(revenueOptimizationInterval, batchInterval);

		// Set DVR Controls summary.
		String startTime = prefs.getString(
				PlaybackManager.SETTINGS_DVR_START_TIME,
				String.valueOf(PlaybackManager.CUSTOM_DVR_START_TIME));
		setSummary(dvrStartTime, startTime);
		String offset = prefs.getString(PrimetimeReference.SETTINGS_DVR_SEEKING_OFFSET,
				String.valueOf(PrimetimeReference.DEFAULT_DVR_SEEKING_OFFSET));
		setSummary(dvrSeekingOffset, offset);

		// Set buffer control summary.
		String initBufferTime = prefs.getString(
				PlaybackManager.SETTINGS_BUFFER_INIT,
				String.valueOf(PlaybackManager.DEFAULT_INIT_BUFFER));
		String bufferTime = prefs.getString(
				PlaybackManager.SETTINGS_BUFFER_TIME,
				String.valueOf(PlaybackManager.DEFAULT_BUFFER_TIME));
		setHeaderSummary(R.id.settingsBufferControl, "Init: " + initBufferTime
				+ ", Buffer: " + bufferTime);
		setSummary(bufferInitET, initBufferTime);
		setSummary(bufferTimeET, bufferTime);

		// Set custom cues summary.
		String customAdCues = prefs.getString(
				AdsManager.SETTINGS_CUSTOM_AD_CUES, "");
		String subscribedCues = prefs.getString(
				AdsManager.SETTINGS_SUBSCRIBED_CUES, "");
		setSummary(customAdCuesET, customAdCues);
		setSummary(subscribedCuesET, subscribedCues);

		// Show ABR Policy Summary as string.
		String abrPolicy = prefs.getString(PlaybackManager.SETTINGS_ABR_POLICY,
				String.valueOf(ABRControlParameters.ABRPolicy.ABR_CONSERVATIVE
						.getValue()));
		value = "";
		try {
			String[] verbArray = getResources().getStringArray(
					R.array.abr_policies);
			value = verbArray[Integer.parseInt(abrPolicy)];
		} catch (Exception e) {
			PrimetimeReference.logger.w(LOG_TAG + "#setPrefSummaries",
					"Exception triggered: " + e.getMessage());
		}
		setSummary(abrPolicyLV, value);


        // Set VA Controls summary.
        String trackingServer = prefs.getString(VAManager.SETTINGS_VA_TRACKING_SERVER, String.valueOf(VAManager.DEFAULT_VA_TRACKING_SERVER));
        setSummary(vaTrackingServer, trackingServer);
        String publisher = prefs.getString(VAManager.SETTINGS_VA_PUBLISHER, String.valueOf(VAManager.DEFAULT_VA_PUBLISHER));
		setSummary(vaPublisher, publisher);
        String channel = prefs.getString(VAManager.SETTINGS_VA_CHANNEL, String.valueOf(VAManager.DEFAULT_VA_CHANNEL));
        setSummary(vaChannel, channel);
		 String playerName = prefs.getString(VAManager.SETTINGS_VA_PLAYER_NAME, String.valueOf(VAManager.DEFAULT_VA_PLAYER_NAME));
        setSummary(vaPlayerName, playerName);

        Boolean moduleEnabled = prefs.getBoolean(VAManager.SETTINGS_VA_ENABLED, VAManager.DEFAULT_VA_ENABLED);
		setSummary(vaModuleEnabled, booleanToString(moduleEnabled));
		Boolean debugLogging = prefs.getBoolean(VAManager.SETTINGS_VA_DEBUG_LOGGING_ENABLED, VAManager.DEFAULT_VA_DEBUG_LOGGING);
        setSummary(vaEnableDebugLoggingCB, booleanToString(debugLogging));
        Boolean quietMode = prefs.getBoolean(VAManager.SETTINGS_VA_QUITE_MODE, VAManager.DEFAULT_VA_QUITE_MODE);
		setSummary(vaEnableQuietModeCB, booleanToString(quietMode));
		Boolean metadataBlocks = prefs.getBoolean(VAManager.SETTINGS_VA_METADATA_BLOCKS_ENABLED, VAManager.DEFAULT_VA_METADATA_BLOCKS_ENABLED);
		setSummary(vaEnableMetadataBlocksCB, booleanToString(metadataBlocks));
		Boolean useSSL = prefs.getBoolean(VAManager.SETTINGS_VA_USE_SSL_ENABLED, VAManager.DEFAULT_VA_USE_SSL);
		setSummary(vaEnableUseSslCB, booleanToString(useSSL));
		Boolean chapterTracking = prefs.getBoolean(VAManager.SETTINGS_VA_CHAPTER_TRACKING_ENABLED, VAManager.DEFAULT_VA_CHAPTER_TRACKING);
		setSummary(vaEnableChapterTrackingCB, booleanToString(chapterTracking));

        setHeaderSummary(R.id.settingsVAConfig, booleanToString(moduleEnabled));

		// set Billing Controls summary
		for (SettingsFeature sf : billingPreferences)
		{
			sf.setSummary(prefs);
			if (sf.isHeaderSummary)
				setHeaderSummary(R.id.settingsBillingConfig, sf.getHeaderSummary(prefs));
		}

        // Set CC style summary.
		setSummary(ccFontLV,
				prefs.getString(CCManager.SETTINGS_CC_STYLE_FONT, null));
		setSummary(ccFillColorLV,
				prefs.getString(CCManager.SETTINGS_CC_STYLE_FILL_COLOR, null));
		setSummary(ccFontColorLV,
				prefs.getString(CCManager.SETTINGS_CC_STYLE_FONT_COLOR, null));
		setSummary(ccFontEdgeLV,
				prefs.getString(CCManager.SETTINGS_CC_STYLE_FONT_EDGE, null));
		setSummary(ccSizeLV,
				prefs.getString(CCManager.SETTINGS_CC_STYLE_SIZE, null));
		setSummary(ccEdgeColorLV,
				prefs.getString(CCManager.SETTINGS_CC_STYLE_EDGE_COLOR, null));
		setSummary(ccBackgroundColorLV, prefs.getString(
				CCManager.SETTINGS_CC_STYLE_BACKGROUND_COLOR, null));
				
		String inset = prefs.getString(CCManager.SETTINGS_CC_STYLE_BOTTOM_INSET, TextFormat.DEFAULT_BOTTOM_INSET); 
		setSummary(ccBottomInset, inset.toUpperCase());
		setSummary(ccSafeArea, prefs.getString(CCManager.SETTINGS_CC_STYLE_SAFE_AREA, TextFormat.DEFAULT_SAFE_AREA).toUpperCase());
		
		String opacity = prefs.getString(
				CCManager.SETTINGS_CC_STYLE_FONT_OPACITY,
				String.valueOf(TextFormat.DEFAULT_OPACITY));
		if (opacity.equals(String.valueOf(TextFormat.DEFAULT_OPACITY)))
			opacity = "DEFAULT";
		setSummary(ccFontOpacityLV, opacity);
		opacity = prefs.getString(
				CCManager.SETTINGS_CC_STYLE_BACKGROUND_OPACITY,
				String.valueOf(TextFormat.DEFAULT_OPACITY));
		if (opacity.equals(String.valueOf(TextFormat.DEFAULT_OPACITY)))
			opacity = "DEFAULT";
		setSummary(ccBackgroundOpacityLV, opacity);
		
		opacity = prefs.getString(CCManager.SETTINGS_CC_STYLE_FILL_OPACITY, String.valueOf(TextFormat.DEFAULT_OPACITY));
		if (opacity.equals(String.valueOf(TextFormat.DEFAULT_OPACITY)))
			opacity = "DEFAULT";
		setSummary(ccFillOpacityLV, opacity);

		// Set REMOTE LOGGING summary
		Boolean remoteLoggingActive = prefs.getBoolean(
				PrimetimeReference.SETTINGS_REMOTE_LOGGING_ACTIVE, true);
		setHeaderSummary(R.id.settingsRemoteLogging,
				booleanToString(remoteLoggingActive));
		setSummary(remoteLoggingHostET, prefs.getString(
				PrimetimeReference.SETTINGS_REMOTE_LOGGING_HOST,
				getResources().getString(R.string.settingsRemoteLoggingHost)));
		setSummary(remoteLoggingPortET, prefs.getString(
				PrimetimeReference.SETTINGS_REMOTE_LOGGING_PORT,
				getResources().getString(R.string.settingsRemoteLoggingPort)));
		setSummary(remoteLoggingSessionTagET, prefs.getString(
				PrimetimeReference.SETTINGS_REMOTE_LOGGING_SESSION_TAG, getResources()
						.getString(R.string.settingsRemoteLoggingSessionTag)));

		// Set InstantOn summary
		Boolean instantOnControls = prefs.getBoolean(InstantOnManager.SETTINGS_ENABLED, InstantOnManager.DEFAULT_ENABLED);
		setHeaderSummary(R.id.settingsInstantOn, booleanToString(instantOnControls));
		String maxLoad = prefs.getString(InstantOnManager.SETTINGS_MAX_LOAD, String.valueOf(InstantOnManager.DEFAULT_MAX_LOAD));
		setSummary(instantOnMaxLoad, maxLoad);
		String concurrentLoad = prefs.getString(InstantOnManager.SETTINGS_CONCURRENT_LOAD, String.valueOf(InstantOnManager.DEFAULT_CONCURRENT_LOAD));
		setSummary(instantOnConcurrentLoad, concurrentLoad);

	}

	private void initialize(PreferenceHolder holder) {
		prefs = PreferenceManager.getDefaultSharedPreferences(this);

		catalogET = (EditTextPreference) holder
				.findPreference(PrimetimeReference.SETTINGS_CONTENT_URL_KEY);
		catalogList = holder.findPreference(CATALOG_LIST);
		logCountET = (EditTextPreference) holder
				.findPreference(PrimetimeReference.SETTINGS_LOG_MAX_ENTRY_COUNT_KEY);
		logVerbosityList = holder.findPreference(PrimetimeReference.SETTINGS_LOG_VERBOSITY);
		controlBarCB = holder
				.findPreference(PrimetimeReference.SETTINGS_CONTROLBAR_AUTOHIDE);

		ccVisibilityCB = holder.findPreference(CCManager.SETTINGS_CC_VISIBILITY);

		returnHomeCB = holder
				.findPreference(PrimetimeReference.SETTINGS_RETURN_HOME_ON_PLAY_COMPLETE);
		forceOMXALCB = holder
				.findPreference(PlaybackManager.SETTINGS_FORCE_OMXAL);
		qosVisbilityCB = holder
				.findPreference(QosManager.SETTINGS_QOS_VISIBILITY);
		seekInAdCB = holder.findPreference(AdsManager.SETTINGS_SEEK_IN_AD);
		clickableAdsCB = holder
				.findPreference(AdsManager.SETTINGS_CLICKABLE_ADS);
		advertisingWorkflowEnabledCB = holder
				.findPreference(AdsManager.SETTINGS_ADVERTISING_WORKFLOW_ENABLED);
		customAdClientFactoryCB = holder
				.findPreference(AdsManager.SETTINGS_CUSTOM_AD_CLIENT_FACTORY);
		advertisingSignalingModeCB = holder
				.findPreference(AdsManager.SETTINGS_ADVERTISING_SIGNALING_MODE);
		advertisingDelayAdLoadingCB = holder
				.findPreference(AdsManager.SETTINGS_DELAY_AD_LOADING);
		hasPrerollCB = holder
				.findPreference(AdsManager.SETTINGS_HAS_PREROLL);
		clickableAdsCB = holder
				.findPreference(AdsManager.SETTINGS_CLICKABLE_ADS);
		drmPrecacheCB = holder
				.findPreference(DrmManager.SETTINGS_DRM_PRE_CACHE);
		abrEnabledCB = holder
				.findPreference(PlaybackManager.SETTINGS_ABR_CTRL_ENABLED);
		abrInitialBitrate = holder
				.findPreference(PlaybackManager.SETTINGS_ABR_INITIAL_BITRATE);
		abrMinBitrate = holder
				.findPreference(PlaybackManager.SETTINGS_ABR_MIN_BITRATE);
		abrMaxBitrate = holder
				.findPreference(PlaybackManager.SETTINGS_ABR_MAX_BITRATE);
		abrMinTrickplayBitrate = holder
				.findPreference(PlaybackManager.SETTINGS_ABR_MIN_TRICKPLAY_BITRATE);
		abrMaxTrickplayBitrate = holder
				.findPreference(PlaybackManager.SETTINGS_ABR_MAX_TRICKPLAY_BITRATE);
		abrMaxTrickplayBandwidthusage = holder
				.findPreference(PlaybackManager.SETTINGS_ABR_MAX_TRICKPLAY_BANDWIDTHUSAGE);
				
		abrPolicyLV = holder
				.findPreference(PlaybackManager.SETTINGS_ABR_POLICY);
		revenueOptimizationEnabledCB = holder
				.findPreference(PlaybackManager.SETTINGS_REVENUE_OPTIMIZATION);
		revenueOptimizationEndpointUrl = holder
				.findPreference(PlaybackManager.SETTINGS_REVENUE_OPTIMIZATION_ENDPOINT);
		revenueOptimizationAuthString = holder
				.findPreference(PlaybackManager.SETTINGS_REVENUE_OPTIMIZATION_AUTHSTRING);
		revenueOptimizationInterval = holder
				.findPreference(PlaybackManager.SETTINGS_REVENUE_OPTIMIZATION_INTERVAL);
		dvrStartTimeEnabledCB = holder
				.findPreference(PlaybackManager.SETTINGS_DVR_START_TIME_ENABLED);
		dvrStartTime = holder
				.findPreference(PlaybackManager.SETTINGS_DVR_START_TIME);
		dvrSeekingOutsideEnabledCB = holder
				.findPreference(PrimetimeReference.SETTINGS_DVR_SEEKING_OUTSIDE_ENABLED);
		dvrSeekingClpEnabledCB = holder
				.findPreference(PrimetimeReference.SETTINGS_DVR_SEEKING_CLP_ENABLED);
		dvrSeekingOffset = holder
				.findPreference(PrimetimeReference.SETTINGS_DVR_SEEKING_OFFSET);
		bufferInitET = (EditTextPreference) holder
				.findPreference(PlaybackManager.SETTINGS_BUFFER_INIT);
		bufferTimeET = (EditTextPreference) holder
				.findPreference(PlaybackManager.SETTINGS_BUFFER_TIME);
		remoteLoggingActiveCB = holder
				.findPreference(PrimetimeReference.SETTINGS_REMOTE_LOGGING_ACTIVE);
		toastWarningsCB = holder.findPreference(PrimetimeReference.SETTINGS_TOAST_WARNINGS);
		remoteLoggingHostET = (EditTextPreference) holder
				.findPreference(PrimetimeReference.SETTINGS_REMOTE_LOGGING_HOST);
		remoteLoggingPortET = (EditTextPreference) holder
				.findPreference(PrimetimeReference.SETTINGS_REMOTE_LOGGING_PORT);
		remoteLoggingSessionTagET = (EditTextPreference) holder
				.findPreference(PrimetimeReference.SETTINGS_REMOTE_LOGGING_SESSION_TAG);
		customAdCuesET = (EditTextPreference) holder
				.findPreference(AdsManager.SETTINGS_CUSTOM_AD_CUES);
		subscribedCuesET = (EditTextPreference) holder
				.findPreference(AdsManager.SETTINGS_SUBSCRIBED_CUES);

        vaTrackingServer = (EditTextPreference) holder.findPreference(VAManager.SETTINGS_VA_TRACKING_SERVER);
        vaPublisher = (EditTextPreference) holder.findPreference(VAManager.SETTINGS_VA_PUBLISHER); 
        vaChannel = (EditTextPreference) holder.findPreference(VAManager.SETTINGS_VA_CHANNEL); 
        vaEnableDebugLoggingCB = holder.findPreference(VAManager.SETTINGS_VA_DEBUG_LOGGING_ENABLED);
        vaEnableQuietModeCB = holder.findPreference(VAManager.SETTINGS_VA_QUITE_MODE);
        vaModuleEnabled = holder.findPreference(VAManager.SETTINGS_VA_ENABLED);
		vaEnableMetadataBlocksCB = holder.findPreference(VAManager.SETTINGS_VA_METADATA_BLOCKS_ENABLED);
		vaEnableUseSslCB = holder.findPreference(VAManager.SETTINGS_VA_USE_SSL_ENABLED);
		vaEnableChapterTrackingCB = holder.findPreference(VAManager.SETTINGS_VA_CHAPTER_TRACKING_ENABLED);
		vaPlayerName = (EditTextPreference) holder.findPreference(VAManager.SETTINGS_VA_PLAYER_NAME);

		for (SettingsFeature sf : billingPreferences)
		{
			sf.initialize(holder);
		}

		instantOnEnabledCB = holder.findPreference(InstantOnManager.SETTINGS_ENABLED);
		instantOnMaxLoad = (EditTextPreference) holder.findPreference(InstantOnManager.SETTINGS_MAX_LOAD);
		instantOnConcurrentLoad = (EditTextPreference) holder.findPreference(InstantOnManager.SETTINGS_CONCURRENT_LOAD);

		setInitialPrefValues();
		initializeCCStyle(holder);

		// Set the preference listeners, which will update the summaries.
		setListeners(preferenceChangeListener);
		// Set initial summaries.
		setPrefSummaries();
		handleCatalogPref();
		handleAbrPref();
		handleRevenueOptimizationPref();
		handleDVRStartTimePref();
		handleDVRSeekingOutsidePref();
		handleAdvertisingWorkflowPref();
		handleInstantOnPref();
		handleBillingPref();
		handleVAConfigPref();
	}

	private void initializeCCStyle(PreferenceHolder holder) {
	
	    ccFillColorLV = (ListPreference) holder
				.findPreference(CCManager.SETTINGS_CC_STYLE_FILL_COLOR);
		ccFontLV = (ListPreference) holder
				.findPreference(CCManager.SETTINGS_CC_STYLE_FONT);
		ccFontColorLV = (ListPreference) holder
				.findPreference(CCManager.SETTINGS_CC_STYLE_FONT_COLOR);
		ccBackgroundColorLV = (ListPreference) holder
				.findPreference(CCManager.SETTINGS_CC_STYLE_BACKGROUND_COLOR);
		ccEdgeColorLV = (ListPreference) holder
				.findPreference(CCManager.SETTINGS_CC_STYLE_EDGE_COLOR);
		ccSizeLV = (ListPreference) holder
				.findPreference(CCManager.SETTINGS_CC_STYLE_SIZE);
		ccFontEdgeLV = (ListPreference) holder
				.findPreference(CCManager.SETTINGS_CC_STYLE_FONT_EDGE);
		ccFontOpacityLV = (ListPreference) holder
				.findPreference(CCManager.SETTINGS_CC_STYLE_FONT_OPACITY);
		ccBackgroundOpacityLV = (ListPreference) holder
				.findPreference(CCManager.SETTINGS_CC_STYLE_BACKGROUND_OPACITY);
		ccFillOpacityLV = (ListPreference) holder.findPreference(CCManager.SETTINGS_CC_STYLE_FILL_OPACITY); 
		ccBottomInset = (EditTextPreference) holder.findPreference(CCManager.SETTINGS_CC_STYLE_BOTTOM_INSET);  
		ccSafeArea = (EditTextPreference) holder.findPreference(CCManager.SETTINGS_CC_STYLE_SAFE_AREA);

		if (ccFontLV == null || ccFontColorLV == null)
			return;

		// Set list values.
		ccFontLV.setEntries(enumToArray(TextFormat.Font.class));
		ccFontLV.setEntryValues(enumToArray(TextFormat.Font.class));
		if (!prefs.contains(CCManager.SETTINGS_CC_STYLE_FONT))
			ccFontLV.setValueIndex(0);

		ccFontColorLV.setEntries(enumToArray(TextFormat.Color.class));
		ccFontColorLV.setEntryValues(enumToArray(TextFormat.Color.class));
		if (!prefs.contains(CCManager.SETTINGS_CC_STYLE_FONT_COLOR))
			ccFontColorLV.setValueIndex(0);

		ccBackgroundColorLV.setEntries(enumToArray(TextFormat.Color.class));
		ccBackgroundColorLV.setEntryValues(enumToArray(TextFormat.Color.class));
		if (!prefs.contains(CCManager.SETTINGS_CC_STYLE_BACKGROUND_COLOR))
			ccBackgroundColorLV.setValueIndex(0);
			
		ccFillColorLV.setEntries(enumToArray(TextFormat.Color.class));
		ccFillColorLV.setEntryValues(enumToArray(TextFormat.Color.class));
		if (!prefs.contains(CCManager.SETTINGS_CC_STYLE_FILL_COLOR))
			ccFillColorLV.setValueIndex(0); 

		ccEdgeColorLV.setEntries(enumToArray(TextFormat.Color.class));
		ccEdgeColorLV.setEntryValues(enumToArray(TextFormat.Color.class));
		if (!prefs.contains(CCManager.SETTINGS_CC_STYLE_EDGE_COLOR))
			ccEdgeColorLV.setValueIndex(0);

		ccSizeLV.setEntries(enumToArray(TextFormat.Size.class));
		ccSizeLV.setEntryValues(enumToArray(TextFormat.Size.class));
		if (!prefs.contains(CCManager.SETTINGS_CC_STYLE_SIZE))
			ccSizeLV.setValueIndex(0);

		ccFontEdgeLV.setEntries(enumToArray(TextFormat.FontEdge.class));
		ccFontEdgeLV.setEntryValues(enumToArray(TextFormat.FontEdge.class));
		if (!prefs.contains(CCManager.SETTINGS_CC_STYLE_FONT_EDGE))
			ccFontEdgeLV.setValueIndex(0);

		String[] opacityEntries = new String[] { "DEFAULT", "0", "10", "20",
				"30", "40", "50", "60", "70", "80", "90", "100" };
		String[] opacityValues = new String[] { "-1", "0", "10", "20", "30",
				"40", "50", "60", "70", "80", "90", "100" };
		ccFontOpacityLV.setEntries(opacityEntries);
		ccFontOpacityLV.setEntryValues(opacityValues);
		if (!prefs.contains(CCManager.SETTINGS_CC_STYLE_FONT_OPACITY))
			ccFontOpacityLV.setValueIndex(0);

		ccBackgroundOpacityLV.setEntries(opacityEntries);
		ccBackgroundOpacityLV.setEntryValues(opacityValues);
		if (!prefs.contains(CCManager.SETTINGS_CC_STYLE_BACKGROUND_OPACITY))
			ccBackgroundOpacityLV.setValueIndex(0);
			
	   ccFillOpacityLV.setEntries(opacityEntries);
		ccFillOpacityLV.setEntryValues(opacityValues);
		if (!prefs.contains(CCManager.SETTINGS_CC_STYLE_FILL_OPACITY))
			ccFillOpacityLV.setValueIndex(0);  
	}

	/**
	 * @return a custom String representation of the boolean value.
	 */
	private String booleanToString(boolean bool) {
		return bool ? getString(R.string.enabled)
				: getString(R.string.disabled);
	}

	/**
	 * Converts the preference header ID to the preference key string for that
	 * category.
	 */
	private String idToPreference(int id) {
		switch (id) {
            case R.id.settingsContentUrlHeader:
                return "preference_catalog";
            case R.id.settingsLogItemsCount:
                return "preference_log_count";
            case R.id.settingsLogVerbosity:
                return "preference_log_verbosity";
            case R.id.settingsControlBarAutohide:
                return "preference_ctrl_bar";
			case R.id.settingsClosedCaptionsVisibility:
				return "preference_cc_visibility"; 
            case R.id.settingsReturnHomeOnPlaybackComplete:
                return "preference_return_home";
            case R.id.settingsForceOMXAL:
                return "preference_omxal";
            case R.id.settingsQosVisibility:
                return "preference_qos_visibility";
            case R.id.settingsToastWarnings:
                return "preference_toast_warnings";
            case R.id.settingsAbrControl:
                return "preference_abr_controls";
			case R.id.settingsRevenueOptimization:
				return "preference_revenue_optimization";
            case R.id.settingsBufferControl:
                return "preference_buffer";
            case R.id.settingsCCStyle:
                return "preference_cc_style";
            case R.id.settingsRemoteLogging:
                return "preference_remote_logging";
            case R.id.settingsCustomCues:
                return "preference_custom_cues";
            case R.id.settingsCustomAdvertisingWorkflow:
                return "preference_custom_advertising_workflow";
            case R.id.settingsClickableAds:
                return "preference_clickable_ads";
            case R.id.settingsDVRcontrols:
                return "preference_dvr_controls";
            case R.id.settingsVAConfig:
                return "preference_va_config";
			case R.id.settingsInstantOn:
				return "preference_instant_on";
			case R.id.settingsBillingConfig:
				return "preference_billing_config";
			default:
                return null;
        }
    }

	/**
	 * Updates the header summary.
	 * 
	 * @param id
	 *            header ID
	 * @param summary
	 *            header summary text
	 */
	@SuppressLint("NewApi")
	private void setHeaderSummary(int id, String summary) {
		if (!isApi11OrAbove()) {
			// API < 11, we don't have preference headers.
			// Update preference screen summary instead.
			@SuppressWarnings("deprecation")
			Preference pref = findPreference(idToPreference(id));
			if (pref != null) {
				pref.setSummary(summary);
			}
			return;
		}
		if (headers == null) {
			return;
		}
		for (Header header : headers) {
			if (header.id == id) {
				header.summary = summary;
				return;
			}
		}
	}

	private void setListeners(Preference.OnPreferenceChangeListener listener) {
		// The listener updates the summaries, when preference is edited by the
		// user.
		setListener(logCountET, listener);
		setListener(logVerbosityList, listener);
		setListener(controlBarCB, listener);
		setListener(ccVisibilityCB, listener);
		setListener(returnHomeCB, listener);
		setListener(forceOMXALCB, listener);
		setListener(qosVisbilityCB, listener);
		setListener(seekInAdCB, listener);

		setListener(advertisingWorkflowEnabledCB, listener);
		setListener(customAdClientFactoryCB, listener);
		setListener(advertisingSignalingModeCB, listener);
		setListener(advertisingDelayAdLoadingCB, listener);
		setListener(hasPrerollCB, listener);

		setListener(clickableAdsCB, listener);
		setListener(revenueOptimizationEnabledCB, listener);
		setListener(drmPrecacheCB, listener);
		setListener(bufferInitET, listener);
		setListener(bufferTimeET, listener);

		setListener(customAdCuesET, listener);
		setListener(subscribedCuesET, listener);

		setListener(abrInitialBitrate, listener);
		setListener(abrMinBitrate, listener);
		setListener(abrMaxBitrate, listener);
		setListener(abrMinTrickplayBitrate, listener);
		setListener(abrMaxTrickplayBitrate, listener);
		setListener(abrMaxTrickplayBandwidthusage, listener); 
		setListener(abrPolicyLV, listener);

		setListener(revenueOptimizationAuthString, listener);
		setListener(revenueOptimizationEndpointUrl, listener);
		setListener(revenueOptimizationInterval, listener);

		setListener(dvrStartTime, listener);
		setListener(dvrSeekingOffset, listener);
		setListener(dvrSeekingClpEnabledCB, listener);

		setListener(instantOnEnabledCB, listener);
		setListener(instantOnMaxLoad, listener);
		setListener(instantOnConcurrentLoad, listener);

		setListener(ccFontLV, listener);
		setListener(ccFontColorLV, listener);
		setListener(ccBackgroundColorLV, listener);
		setListener(ccFillColorLV, listener);
		setListener(ccEdgeColorLV, listener);
		setListener(ccSizeLV, listener);
		setListener(ccFontEdgeLV, listener);
		setListener(ccFontOpacityLV, listener);
		setListener(ccBackgroundOpacityLV, listener);
		setListener(ccFillOpacityLV, listener); 
		setListener(ccBottomInset, listener);
		setListener(ccSafeArea, listener); 

		setListener(remoteLoggingActiveCB, listener);
		setListener(toastWarningsCB, listener);
		setListener(remoteLoggingHostET, listener);
		setListener(remoteLoggingPortET, listener);
		setListener(remoteLoggingSessionTagET, listener);

        setListener(vaTrackingServer, listener);
        setListener(vaPublisher, listener);
        setListener(vaChannel, listener);
        setListener(vaEnableDebugLoggingCB, listener);
        setListener(vaEnableQuietModeCB, listener);
        setListener(vaModuleEnabled, listener);
		setListener(vaEnableMetadataBlocksCB, listener);
		setListener(vaEnableUseSslCB, listener);
		setListener(vaEnableChapterTrackingCB, listener);
		setListener(vaPlayerName, listener);

		for (SettingsFeature sf : billingPreferences)
		{
			sf.setListener(listener);
		}

    }

	private static void setListener(Preference pref, Preference.OnPreferenceChangeListener listener) {
		if (pref == null)
			return;
		pref.setOnPreferenceChangeListener(listener);
	}

	/**
	 * Force the headers to update their summaries.
	 */
	@TargetApi(Build.VERSION_CODES.HONEYCOMB)
	public void invalidateHeaders() {
		if (isApi11OrAbove()) {
			super.invalidateHeaders();
		} else {
			this.onContentChanged();
			getListView().invalidate();
		}
	}

	private static void setSummary(Preference pref, String summary) {
		if (pref == null)
			return;
		pref.setSummary(summary);
	}

	private void handleCatalogPref() {
		if (catalogList == null || catalogET == null)
			return;
		// Listen for catalog list selection.
		// Update EditText when that happens.
		OnPreferenceChangeListener listener = new OnPreferenceChangeListener() {

			@Override
			public boolean onPreferenceChange(Preference preference, Object newValue) {
				if (preference.getKey().equals(CATALOG_LIST)) {
					catalogET.setText((String) newValue);
				}
				setSummary(catalogET, (String) newValue);
				setSummary(catalogList, (String) newValue);

				return preferenceChangeListener.onPreferenceChange(preference, newValue);
			}
		};
		catalogList.setOnPreferenceChangeListener(listener);
		catalogET.setOnPreferenceChangeListener(listener);
	}

	private void setCatalogListEntries()
	{
		if (catalogList == null) return;

		try {
			AssetManager am = getResources().getAssets();
			String assets[] = am.list("catalogs");
			String entries[] = new String[assets.length + 1];
			entries[0] = getString(R.string.contentUrl);
			for (int i = 0; i < assets.length; i++)
				entries[i + 1] = "catalogs/" + assets[i];

			((ListPreference) catalogList).setEntries(entries);
			((ListPreference) catalogList).setEntryValues(entries);
		}
		catch (IOException e)
		{

		}
	}

	private void handleAbrPref() {
		if (abrEnabledCB == null)
			return;
		// Listen for ABR enable/disable event.
		OnPreferenceChangeListener listener = new OnPreferenceChangeListener() {

			@Override
			public boolean onPreferenceChange(Preference preference,
					Object newValue) {
				setAbrControlsEnabled((Boolean) newValue);
				return preferenceChangeListener.onPreferenceChange(preference,
						newValue);
			}
		};
		abrEnabledCB.setOnPreferenceChangeListener(listener);
		boolean enabled = prefs.getBoolean(
				PlaybackManager.SETTINGS_ABR_CTRL_ENABLED,
				PlaybackManager.DEFAULT_ABR_CTRL_ENABLED);
		setAbrControlsEnabled(enabled);
	}

	private void setAbrControlsEnabled(boolean enabled) {
		if (abrInitialBitrate != null)
			abrInitialBitrate.setEnabled(enabled);
		if (abrMinBitrate != null)
			abrMinBitrate.setEnabled(enabled);
		if (abrMaxBitrate != null)
			abrMaxBitrate.setEnabled(enabled);
		if (abrMinTrickplayBitrate != null)
			abrMinTrickplayBitrate.setEnabled(enabled);
		if (abrMaxTrickplayBitrate != null)
			abrMaxTrickplayBitrate.setEnabled(enabled);
		if (abrMaxTrickplayBandwidthusage != null)
			abrMaxTrickplayBandwidthusage.setEnabled(enabled); 
		if (abrPolicyLV != null)
			abrPolicyLV.setEnabled(enabled);
	}

	private void handleRevenueOptimizationPref() {
		if (revenueOptimizationEnabledCB == null) {
			return;
		}
		// Listen for ads logging enable/disable event.
		OnPreferenceChangeListener listener = new OnPreferenceChangeListener() {

			@Override
			public boolean onPreferenceChange(Preference preference,
											  Object newValue) {
				setRevenueOptimizationEnabled((Boolean) newValue);
				return preferenceChangeListener.onPreferenceChange(preference,
						newValue);
			}
		};
		revenueOptimizationEnabledCB.setOnPreferenceChangeListener(listener);
		boolean enabled = prefs.getBoolean(
				PlaybackManager.SETTINGS_REVENUE_OPTIMIZATION,
				PlaybackManager.DEFAULT_REVENUE_OPTIMIZATION);
		setRevenueOptimizationEnabled(enabled);
	}

	private void setRevenueOptimizationEnabled(boolean enabled) {
		if (revenueOptimizationAuthString != null) {
			revenueOptimizationAuthString.setEnabled(enabled);
		}
		if (revenueOptimizationEndpointUrl != null) {
			revenueOptimizationEndpointUrl.setEnabled(enabled);
		}
		if (revenueOptimizationInterval != null) {
			revenueOptimizationInterval.setEnabled(enabled);
		}
	}

	private void handleInstantOnPref() {
		if (instantOnEnabledCB == null)
			return;

		OnPreferenceChangeListener listener = new OnPreferenceChangeListener() {
			@Override
			public boolean onPreferenceChange(Preference preference, Object newValue) {
				setInstantOnControlsEnabled((Boolean) newValue);
				return preferenceChangeListener.onPreferenceChange(preference, newValue);
			}
		};
		instantOnEnabledCB.setOnPreferenceChangeListener(listener);
		boolean enabled = prefs.getBoolean(InstantOnManager.SETTINGS_ENABLED, InstantOnManager.DEFAULT_ENABLED);
		setInstantOnControlsEnabled(enabled);
	}

	private void setInstantOnControlsEnabled(boolean enabled)
	{
		if (instantOnConcurrentLoad != null)
			instantOnConcurrentLoad.setEnabled(enabled);
		if (instantOnMaxLoad != null)
			instantOnMaxLoad.setEnabled(enabled);
	}

	private void handleBillingPref() {
		if (billingPreferences == null)
			return;

		OnPreferenceChangeListener listener = new OnPreferenceChangeListener() {
			@Override
			public boolean onPreferenceChange(Preference preference, Object newValue) {
				for (SettingsFeature sf : billingPreferences)
				{
					if (!sf.isHeaderSummary)
						sf.setEnabled((Boolean)newValue);
				}

				return preferenceChangeListener.onPreferenceChange(preference, newValue);
			}
		};

		boolean current = true;
		for (SettingsFeature sf : billingPreferences)
		{
			if (sf.isHeaderSummary)
			{
				sf.setListener(listener);
				current = sf.getHeaderSummary(prefs).equals(getString(R.string.customConfiguration));
				break;
			}
		}

		for (SettingsFeature sf : billingPreferences)
		{
			if (!sf.isHeaderSummary)
			{
				sf.setEnabled(current);
			}
		}
	}


	private void handleAdvertisingWorkflowPref() {
		if (advertisingWorkflowEnabledCB == null)
			return;

		OnPreferenceChangeListener listener = new OnPreferenceChangeListener() {

			@Override
			public boolean onPreferenceChange(Preference preference,
					Object newValue) {
				setAdvertisingWorkflowControlsEnabled((Boolean) newValue);
				return preferenceChangeListener.onPreferenceChange(preference,
						newValue);
			}
		};
		advertisingWorkflowEnabledCB.setOnPreferenceChangeListener(listener);
		boolean enabled = prefs.getBoolean(
				AdsManager.SETTINGS_ADVERTISING_WORKFLOW_ENABLED,
				AdsManager.DEFAULT_ADVERTISING_WORKFLOW_ENABLED);
		setAdvertisingWorkflowControlsEnabled(enabled);
	}

	private void setAdvertisingWorkflowControlsEnabled(boolean enabled) {
		if (advertisingSignalingModeCB != null)
			advertisingSignalingModeCB.setEnabled(enabled);
		if (advertisingDelayAdLoadingCB != null)
			advertisingDelayAdLoadingCB.setEnabled(enabled);
		if (customAdClientFactoryCB != null)
			customAdClientFactoryCB.setEnabled(enabled);
		if (hasPrerollCB != null)
			hasPrerollCB.setEnabled(enabled);
	}
	
	private void handleVAConfigPref() {       
		if (vaModuleEnabled == null)
			return;
		// Listen for VA enable/disable event.
		OnPreferenceChangeListener listener = new OnPreferenceChangeListener() {

			@Override
			public boolean onPreferenceChange(Preference preference, Object newValue) {
				setVAConfigEnabled((Boolean) newValue);
				return preferenceChangeListener.onPreferenceChange(preference, newValue);
			}
		};
		vaModuleEnabled.setOnPreferenceChangeListener(listener);
		boolean enabled = prefs.getBoolean(VAManager.SETTINGS_VA_ENABLED, VAManager.DEFAULT_VA_ENABLED);
		setVAConfigEnabled(enabled);
	}

	private void setVAConfigEnabled(boolean enabled) {  
		if (vaPlayerName != null)
			vaPlayerName.setEnabled(enabled);
		if (vaTrackingServer != null)
			vaTrackingServer.setEnabled(enabled);

		if (vaPublisher != null)
			vaPublisher.setEnabled(enabled);
		if (vaChannel != null)
			vaChannel.setEnabled(enabled);
		if (vaEnableDebugLoggingCB != null)
			vaEnableDebugLoggingCB.setEnabled(enabled);

		if (vaEnableQuietModeCB != null)
			vaEnableQuietModeCB.setEnabled(enabled);
		if (vaEnableMetadataBlocksCB != null)
			vaEnableMetadataBlocksCB.setEnabled(enabled);
		if (vaEnableUseSslCB != null)
			vaEnableUseSslCB.setEnabled(enabled);
		if (vaEnableChapterTrackingCB != null)
			vaEnableChapterTrackingCB.setEnabled(enabled); 

	}
	private void handleDVRStartTimePref() {
		if (dvrStartTimeEnabledCB == null)
			return;
		// Listen for DVR start time enable/disable event.
		OnPreferenceChangeListener listener = new OnPreferenceChangeListener() {

			@Override
			public boolean onPreferenceChange(Preference preference,
					Object newValue) {
				setDVRControlsStartTimeEnabled((Boolean) newValue);
				return preferenceChangeListener.onPreferenceChange(preference,
						newValue);
			}
		};
		dvrStartTimeEnabledCB.setOnPreferenceChangeListener(listener);
		boolean enabled = prefs.getBoolean(
				PlaybackManager.SETTINGS_DVR_START_TIME_ENABLED,
				PlaybackManager.DEFAULT_DVR_START_TIME_ENABLED);
		setDVRControlsStartTimeEnabled(enabled);
	}

	private void handleDVRSeekingOutsidePref() {
		if (dvrSeekingOutsideEnabledCB == null)
			return;

		// Listen for DVR seeking outside window enable/disable event.
		OnPreferenceChangeListener listener = new OnPreferenceChangeListener() {

			@Override
			public boolean onPreferenceChange(Preference preference,
					Object newValue) {
				setDVRControlsSeekingOutsideEnabled((Boolean) newValue);
				return preferenceChangeListener.onPreferenceChange(preference,
						newValue);
			}
		};
		dvrSeekingOutsideEnabledCB.setOnPreferenceChangeListener(listener);
		boolean enabledCustomSeeking = prefs.getBoolean(
				PrimetimeReference.SETTINGS_DVR_SEEKING_OUTSIDE_ENABLED,
				PrimetimeReference.DEFAULT_DVR_SEEKING_OUTSIDE_ENABLED);
		setDVRControlsSeekingOutsideEnabled(enabledCustomSeeking);
	}

	private void setDVRControlsStartTimeEnabled(boolean enabled) {
		if (dvrStartTime != null) {
			dvrStartTime.setEnabled(enabled);
		}
	}

	private void setDVRControlsSeekingOutsideEnabled(boolean enabled) {
		if (dvrSeekingClpEnabledCB != null) {
			dvrSeekingClpEnabledCB.setEnabled(enabled);
		}
		if (dvrSeekingOffset != null) {
			dvrSeekingOffset.setEnabled(enabled);
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.actionbar_settings, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			PrimetimeReference.logger.i(LOG_TAG + "#onOptionsItemSelected",
					"Home action bar item activated.");
			finish();
			return true;

		case R.id.ActionBarAbout:
			PrimetimeReference.logger.i(LOG_TAG + "#onOptionsItemSelected",
					"About action bar item activated.");
			PrimetimeReference.showAbout(this);
			return true;

		default:
			return super.onOptionsItemSelected(item);
		}
	}

	/**
	 * Checks to see if using new v11+ way of handling PrefsFragments.
	 * 
	 * @return Returns false pre-v11, else checks to see if using headers.
	 */
	public boolean isApi11OrAbove() {
		if (mHasHeaders != null && mLoadHeaders != null) {
			try {
				return (Boolean) mHasHeaders.invoke(this);
			} catch (Exception e) {
				PrimetimeReference.logger.w(LOG_TAG + "#isApi11OrAbove",
						"Exception triggered: " + e.getMessage());
			}
		}
		return false;
	}

	Preference.OnPreferenceChangeListener preferenceChangeListener = new Preference.OnPreferenceChangeListener() {
		@TargetApi(Build.VERSION_CODES.HONEYCOMB)
		@Override
		public boolean onPreferenceChange(Preference preference, Object newValue) {
			// Save new value in order to update summaries.
			Editor editor = prefs.edit();
			if (newValue instanceof String) {
				preferenceChanged = !prefs.getString(preference.getKey(), "").equals(newValue);
				editor.putString(preference.getKey(), (String) newValue);
			} else if (newValue instanceof Boolean) {
				preferenceChanged = prefs.getBoolean(preference.getKey(), false) != (Boolean) newValue;
				editor.putBoolean(preference.getKey(), (Boolean) newValue);
			} else {
				preferenceChanged = true;
			}
			editor.commit();

			// Update preferences summaries.
			setPrefSummaries();
			invalidateHeaders();
			return true;
		}
	};

    @Override
    public boolean isValidFragment(String fragmentName)
    {
        return SettingsActivity.PrefsFragment.class.getName().equals(fragmentName);
    }


	private abstract class SettingsFeature {

		Preference preference;
		String key;
		boolean isHeaderSummary;

		public void setInitialPreferences(SharedPreferences preferences) {
			Editor editor = preferences.edit();
			if (editor != null && !preferences.contains(key))
			{
				putEditor(editor);
				editor.commit();
			}
		}

		abstract protected void putEditor(Editor editor);

		abstract protected String getSummary(SharedPreferences preferences);

		public void setSummary(SharedPreferences preferences) {
			if (preference != null) {
				String summary = getSummary(preferences);
				preference.setSummary(summary);
			}
		}

		public String getHeaderSummary(SharedPreferences preferences) {
			return getSummary(preferences);
		}

		public void initialize(PreferenceHolder holder) {
			preference = holder.findPreference(key);
		}

		public void setListener(OnPreferenceChangeListener listener) {
			if (preference != null) {
				preference.setOnPreferenceChangeListener(listener);
			}
		}

		public void setEnabled(boolean enabled)
		{
			if (preference != null) {
				preference.setEnabled(enabled);
			}
		}

	}

	private class StringSettingsFeature extends SettingsFeature {
		String value;

		StringSettingsFeature(String key, String value) {
			this.key = key;
			this.value = value;
		}

		StringSettingsFeature(String key, String value, boolean header) {
			this(key, value);
			this.isHeaderSummary = header;
		}

		@Override
		protected void putEditor(Editor editor)
		{
			editor.putString(key, value);
		}

		@Override
		protected String getSummary(SharedPreferences preferences)
		{
			return preferences.getString(key, value);
		}
	}

	private class BooleanSettingsFeature extends SettingsFeature {

		boolean value;

		BooleanSettingsFeature(String key, boolean value)
		{
			this.key = key;
			this.value = value;
		}

		BooleanSettingsFeature(String key, boolean value, boolean header)
		{
			this(key, value);
			this.isHeaderSummary = header;
		}

		@Override
		protected void putEditor(Editor editor)
		{
			editor.putBoolean(key, value);
		}

		@Override
		protected String getSummary(SharedPreferences preferences)
		{
			boolean summary = preferences.getBoolean(key, value);
			return summary ? getString(R.string.enabled) : getString(R.string.disabled);
		}

	}

	private class CustomBooleanSettingsFeature extends BooleanSettingsFeature {
		CustomBooleanSettingsFeature(String key, boolean value) {
			super(key, value);
		}
		CustomBooleanSettingsFeature(String key, boolean value, boolean header) {
			super(key, value, header);
		}

		@Override
		protected String getSummary(SharedPreferences preferences)
		{
			boolean summary = preferences.getBoolean(key, value);
			return summary ? getString(R.string.customConfiguration) : getString(R.string.defaultConfiguration);
		}
	}

	private class FloatSettingsFeature extends SettingsFeature {
		float value;

		FloatSettingsFeature(String key, float value)
		{
			this.key = key;
			this.value = value;
		}

		FloatSettingsFeature(String key, float value, boolean header)
		{
			this(key, value);
			this.isHeaderSummary = header;
		}

		@Override
		protected void putEditor(Editor editor)
		{
			editor.putFloat(key, value);
		}

		@Override
		protected String getSummary(SharedPreferences preferences)
		{
			float summary = preferences.getFloat(key, value);
			return String.valueOf(summary);
		}

	}
}

/**
 * Offers the possibility to threat the PreferenceActivity and the
 * PreferenceFragment in a unified way.
 */
interface PreferenceHolder {
	Preference findPreference(CharSequence key);
}
