Code example for EditTextPreference

Methods: setIntentsetOnPreferenceClickListenersetSummary, getText

0
		super.onResume(); 
		// register pref change listener 
		getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
		 
		//TODO updatePreferences() containing following and others 
		pEtFolder.setSummary(pEtFolder.getText());
		setFolderPreferenceClickIntent(); 
		updateIntervalSummary(); 
		updateIntervalTypesEnabled(); 
		updatePTpDailyTime(); 
	} 
 
	// release the sharedPreferenceListener 
	@Override 
	protected void onPause() 
	{ 
		super.onPause(); 
		getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
	} 
	 
	@Override 
	protected void onStop() 
	{ 
		super.onStop(); 
		 
		Intent updateIntent = new Intent(getApplicationContext(), UpdateAlarmsService.class);
		startService(updateIntent);
	} 
	 
	 
	//// custom handling of some preferences 
 
	private void initPreferences() 
	{ 
		//pCbServiceActive = (CheckBoxPreference) findPreference(getString(R.string.pref_key_service_active)); 
		 
		pEtFolder = (EditTextPreference) findPreference(getString(R.string.pref_key_target_folder));
		//pCbRecursiveDelete = (CheckBoxPreference) findPreference(getString(R.string.pref_key_use_recursive_delete)); 
		//pCbDeleteFolders = (CheckBoxPreference) findPreference(getString(R.string.pref_key_delete_folders)); 
		//pCbNotifyOnDelete = (CheckBoxPreference) findPreference(getString(R.string.pref_key_notify_on_delete)); 
		 
		pCbIntervalType = (CheckBoxPreference) findPreference(getString(R.string.pref_key_interval_type));
		pTpDailyTime = (TimePreference) findPreference(getString(R.string.pref_key_daily_at));
		pEtIntervalMinutes = (EditTextPreference) findPreference(getString(R.string.pref_key_periodic_at));
		//pCbStrictInterval =  (CheckBoxPreference) findPreference(getString(R.string.pref_key_use_strict_alarms)); 
		 
		pCbUseExtensionFilter = (CheckBoxPreference) findPreference(getString(R.string.pref_key_use_filter_extensions));
		pCbDeleteExtensionMatches = (CheckBoxPreference) findPreference(getString(R.string.pref_key_delete_files_matching_extension));
		pEtExtensionsFilter = (EditTextPreference) findPreference(getString(R.string.pref_key_filter_extensions));
		pCbUsePatternFilter = (CheckBoxPreference) findPreference(getString(R.string.pref_key_use_filter_pattern));
		pCbDeletePatternMatches = (CheckBoxPreference) findPreference(getString(R.string.pref_key_delete_files_matching_pattern));
		pEtPatternFilter = (EditTextPreference) findPreference(getString(R.string.pref_key_filter_pattern));
		 
	} 
	 
	 
	 
	//// override onPreferenceClick and onPreferenceChange 
	 
	@Override 
	public boolean onPreferenceClick(Preference preference)
	{ 
		// Folder preference 
		if (preference.equals(pEtFolder))
		{ 
//			// disable the EditText dialog (and soft keyboard) as we're using a file picking intent instead 
			pEtFolder.getDialog().dismiss();
			 
			// pick folder 
			pEtFolderGetFolder(); 
			return true; 
		} 
		 
		// Interval Preference 
		else if (preference.equals(pEtIntervalMinutes))
		{ 
			// update the preference summary with the new value 
			updateIntervalSummary(); 
			return true; 
		} 
		 
		// for all other clicks 
		return true; 
	} 
	 
	@Override 
	public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
	{ 
		if (key.equals(pEtIntervalMinutes.getKey()))
		{ 
			updateIntervalSummary(); 
		} 
		else if (key.equals(pCbIntervalType.getKey()))
		{ 
			updateIntervalTypesEnabled(); 
		} 
		else if (key.equals(pTpDailyTime.getKey()))
		{ 
			updatePTpDailyTime(); 
		} 
		 
	} 
	 
	//// custom preference updates and actions 
	//TODO see what the common actions are and method(pref) them 
	 
	private void setFolderPreferenceClickIntent() 
	{ 
		Intent folderIntent = new Intent(this, FileExplore.class);
		pEtFolder.setIntent(folderIntent);
		pEtFolder.setOnPreferenceClickListener(this);
	} 
	 
	private void updateFolderPreference(Intent receivedIntent)
	{ 
		String selectedFolderPath = receivedIntent.getStringExtra(