@SuppressWarnings("deprecation") public PreferenceScreen preferenceScreen(final PreferenceActivity activity) { PreferenceManager manager = activity.getPreferenceManager(); PreferenceScreen screen = manager.createPreferenceScreen(activity); screen.setTitle(this._name); String type = activity.getString(R.string.type_trigger_unknown); if (this instanceof ProbeTrigger) type = activity.getString(R.string.type_trigger_probe); if (this instanceof DateTrigger) type = activity.getString(R.string.type_trigger_datetime); screen.setSummary(type); final Trigger me = this; Preference viewAction = new Preference(activity); viewAction.setTitle(R.string.label_trigger_show_action); viewAction.setSummary(R.string.label_trigger_show_action_desc); viewAction.setOrder(Integer.MAX_VALUE); viewAction.setOnPreferenceClickListener( new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { Intent intent = new Intent(activity, CodeViewerActivity.class); intent.putExtra(CodeViewerActivity.SOURCE_CODE, me._action); intent.putExtra(CodeViewerActivity.TITLE, me.name()); activity.startActivity(intent); return true; } }); screen.addPreference(viewAction); CheckBoxPreference enabled = new CheckBoxPreference(activity); enabled.setTitle(R.string.label_trigger_enable_action); enabled.setSummary(R.string.label_trigger_enable_action_desc); enabled.setKey(this.enabledKey()); enabled.setDefaultValue(true); enabled.setOrder(Integer.MAX_VALUE); enabled.setOnPreferenceChangeListener( new Preference.OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { return true; } }); screen.addPreference(enabled); Preference fireNow = new Preference(activity); fireNow.setTitle(R.string.label_trigger_fire_now); fireNow.setSummary(R.string.label_trigger_fire_now_desc); fireNow.setOrder(Integer.MAX_VALUE / 2); fireNow.setOnPreferenceClickListener( new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { me.execute(activity, true); return true; } }); screen.addPreference(fireNow); return screen; }
private static void setupPreferences(PreferenceActivity context) { // create Categories PreferenceScreen prefScreen = context.getPreferenceManager().createPreferenceScreen(context); prefScreen.removeAll(); // selected location category PreferenceCategory selectedCat = new PreferenceCategory(context); selectedCat.setTitle(R.string.selected_location_str); // location list category PreferenceCategory locationListCat = new PreferenceCategory(context); locationListCat.setTitle(R.string.location_list_str); // general category PreferenceCategory generalCat = new PreferenceCategory(context); generalCat.setTitle(R.string.general_preferences_str); // //gesture category // PreferenceCategory gestureCat = new PreferenceCategory(context); // gestureCat.setTitle(R.string.gesture_settings_str); // add categories to preference screen prefScreen.addPreference(selectedCat); prefScreen.addPreference(locationListCat); // prefScreen.addPreference(gestureCat); prefScreen.addPreference(generalCat); // Create add and delete location preferences and add to location list locationListCat.addPreference( createAddLocationPreference( context, context.getString(R.string.add_location_str), context.getString(R.string.add_location_description_str))); locationListCat.addPreference( createDeleteLocationPreference( context, context.getString(R.string.delete_location_str), context.getString(R.string.delete_location_description_str))); // create apptheme action preference generalCat.addPreference( createIntListPreference( context, PREF_APP_THEME, R.string.pref_app_theme, R.string.pref_app_theme_description, R.array.app_theme_strings, R.array.app_theme_values, "0")); // create mythfrontend update status interval preference generalCat.addPreference( createIntListPreference( context, PREF_STATUS_UPDATE_INTERVAL, R.string.status_update_interval_str, R.string.status_update_interval_description_str, R.array.status_Update_Interval_strings, R.array.status_Update_Interval_values, "0")); // create haptic feedback shared preference generalCat.addPreference( createCheckBox( context, PREF_HAPTIC_FEEDBACK_ENABLED, R.string.haptic_feedback_enabled_str, R.string.haptic_feedback_enabled_description_str, false)); // create longpress action preference generalCat.addPreference( createIntListPreference( context, PREF_LONGPRESS_ACTION, R.string.longpress_action_str, R.string.longpress_action_description_str, R.array.longpress_action_strings, R.array.longpress_action_values, "0")); // create key repeat interval preference generalCat.addPreference( createIntListPreference( context, PREF_KEY_REPEAT_INTERVAL, R.string.key_repeat_interval_str, R.string.key_repeat_interval_description_str, R.array.key_repeat_interval_strings, R.array.key_repeat_interval_values, "100")); // create connection timeout interval preference generalCat.addPreference( createIntListPreference( context, PREF_CONNECTION_TIMEOUT_INTERVAL, R.string.conection_timeout_interval_str, R.string.conection_timeout_interval_description_str, R.array.connection_timeout_interval_strings, R.array.connection_timeout_interval_values, "5000")); // create donate button visible checkbox generalCat.addPreference( createCheckBox( context, PREF_SHOW_DONATE_MENU_ITEM, R.string.show_donate_menu_item_str, R.string.show_donate_menu_item_str, true)); // //create gestures enabled // gestureCat.addPreference(createCheckBox(context, // PREF_GESTURES_ENABLED, // R.string.gestures_enabled_str, // R.string.gestures_enabled_str, false)); // // //gesture list preference // Preference gestureList = createGestureListPreference(context); // gestureCat.addPreference(gestureList); // open DB MythMoteDbManager _dbAdapter = new MythMoteDbManager(context); _dbAdapter.open(); // get list of locations Cursor cursor = _dbAdapter.fetchAllFrontendLocations(); // get column indexes sIdIndex = cursor.getColumnIndex(MythMoteDbHelper.KEY_ROWID); sAddressIndex = cursor.getColumnIndex(MythMoteDbHelper.KEY_ADDRESS); sNameIndex = cursor.getColumnIndex(MythMoteDbHelper.KEY_NAME); sPortIndex = cursor.getColumnIndex(MythMoteDbHelper.KEY_PORT); sMacIndex = cursor.getColumnIndex(MythMoteDbHelper.KEY_MAC); sWifiOnlyIndex = cursor.getColumnIndex(MythMoteDbHelper.KEY_WIFIONLY); // determine if we have locations saved int count = cursor.getCount(); if (count > 0 && cursor.moveToFirst()) { // get selected frontend id int selected = context .getSharedPreferences(MYTHMOTE_SHARED_PREFERENCES_ID, MODE_PRIVATE) .getInt(MythMotePreferences.PREF_SELECTED_LOCATION, -1); // if selected failed if (selected == -1) { // set to first in list selected = cursor.getInt(sIdIndex); // save (defaulted) selected location SaveSelectedLocationId(context, selected); } // put each location in the preference list for (int i = 0; i < count; i++) { locationListCat.addPreference( MythMotePreferences.createLocationPreference( context, cursor.getString(sIdIndex), cursor.getString(sNameIndex), cursor.getString(sAddressIndex))); if (cursor.getInt(sIdIndex) == selected) { // create preference for selected location selectedCat.addPreference( MythMotePreferences.createSelectedLocationPreference( context, context.getString(R.string.selected_location_str), cursor.getString(sNameIndex))); } cursor.moveToNext(); } // the saved selected location was not found just pick the first one if (selectedCat.getPreferenceCount() <= 0) { cursor.moveToFirst(); selectedCat.addPreference( MythMotePreferences.createSelectedLocationPreference( context, context.getString(R.string.selected_location_str), cursor.getString(sNameIndex))); // save location ID so that it is for real SaveSelectedLocationId(context, cursor.getInt(sIdIndex)); } } else { selectedCat.addPreference( MythMotePreferences.createSelectedLocationPreference( context, context.getString(R.string.selected_location_str), context.getString(R.string.no_frontend_locations_defined_str))); } cursor.close(); _dbAdapter.close(); // set preference screen context.setPreferenceScreen(prefScreen); // Assign dependences // gestureList.setDependency(PREF_GESTURES_ENABLED); }