How to increase brightness of screen on Android? - android

I'm trying to develop an app which change the brightness in a PreferenceActivity but when i choose the item, the app is closed... why??
The Code
<ListPreference
android:key="brillo"
android:title="Luminosidad"
android:summary="Escoge cuanto brillo quieres para jugar"
android:dialogTitle="Selecciona tono"
android:entries="#array/modobrillo"
android:entryValues="#array/codigobrillo"
/>
the arrays
<string-array name="modobrillo">
<item>Nivel Bajo</item>
<item>Nivel Medio</item>
<item>Nivel Alto</item>
<string-array name="codigobrillo">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>
On a Activity I do not even have code... Help!!

Related

Error while recompiling app string.xml

Facing error while recompiling an app.The app was in chinese so I had decompiled it using Advance apktool translated strings.xml but while recompiling it it giving error log attached.
Log Recorded By : Advanced ApkTool v4.1.0 By BDFreak
Blockqu(skipping file '.picasa.ini' due to ANDROID_AAPT_IGNORE pattern '.')
(skipping dir '.picasaoriginals' due to ANDROID_AAPT_IGNORE pattern '.')
F:\Downloads\Compressed\apkmanager\3-Out\tools.apk\res\values\strings.xml:324: error: Error parsing XML: not well-formed (invalid token)
F:\Downloads\Compressed\apkmanager\3-Out\tools.apk\res\values\public.xml:268: error: Public symbol string/add_screenshot declared here is not defined.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="about_module">about desktop toolbox</string>
<string name="add_screenshot">increase screenshots options</string>
<string name="add_screenshot_summary">screenshots option to increase the power menu</string>
<string name="advanced">advanced</string>
<string name="advanced_reboot_menu">advanced restart menu</string>
<string name="advanced_reboot_menu_summary">add more options to "restart" menu</string>
<string name="all_rotations">enable all the rotation angle</string>
<string name="all_rotations_summary">allow all rotation angle , including upside down</string>
<string name="am_pm_style">am pm style</string>
<string name="am_pm_style_summary">choose am pm style: %s</string>
<string name="app_browser">browser</string>
<string name="app_calendar">calendar</string>
<string name="app_miuigallery">gallery</string>
<string name="app_mms">sms</string>
<string name="app_music">music</string>
<string name="app_phone">phone</string>
<string name="app_quicksearchbox">quick search bar</string>
<string name="app_supermarket">app store</string>
<string name="app_themes">themed</string>
<string name="app_updater">system update</string>
<string name="applications">hide checked icon</string>
<string name="applications_summary">miui system application settings</string>
<string name="apps_notifications">notice</string>
<string name="backup_defaults">restore default</string>
<string name="backup_defaults_restored">the default setting has been restored</string>
<string name="backup_delete">delete</string>
<string name="backup_name">backup name</string>
<string name="backup_no_backups">no backup</string>
<string name="backup_restore">restore settings</string>
<string name="backup_restored">restored backup settings</string>
<string name="backup_restoring">restoring a backup</string>
<string name="backup_save">save settings</string>
<string name="backup_save_error">save error !</string>
<string name="backup_save_successful">successfully saved!</string>
<string name="battery">battery</string>
<string name="battery_icon_color">the battery icon color</string>
<string name="battery_icon_color_summary">setting the battery icon color</string>
<string name="battery_text_color">battery text color</string>
<string name="battery_text_color_summary">battery set text color</string>
<string name="bold_settings_font">set bold text</string>
<string name="bold_settings_font_summary">systems and applications using bold style</string>
<string name="browser_autofit_pages">adaptive page</string>
<string name="browser_autofit_pages_summary">adaptive page option to add the browser</string>
<string name="buttons">button</string>
<string name="buttons_summary">key remapping , keystrokes , etc.</string>
<string name="carrier_label_color">operators label color</string>
<string name="carrier_label_color_summary">setting operators label color</string>
<string name="carrier_settings">operators tag</string>
<string name="clock">clock</string>
<string name="clock_center">center</string>
<string name="clock_center_ios7">center (ios 7 style)</string>
<string name="clock_color_summary">setting the status bar clock color</string>
<string name="clock_color_title">clock color</string>
<string name="clock_date_format">date format</string>
<string name="clock_date_style">date style</string>
<string name="clock_date_style_summary">"select the date style:
%s"</string>
<string name="clock_hide">hide clock</string>
<string name="clock_hide_summary">not in the status bar clock</string>
<string name="clock_left">left</string>
<string name="clock_position">clock position</string>
<string name="clock_position_summary">"choose clock location:
%s"</string>
<string name="clock_right">right home ( default )</string>
<string name="clock_style_hide">hide</string>
<string name="clock_style_large">l</string>
<string name="clock_style_small">s</string>
<string name="cloud_upload_delay">cloud sync delay</string>
<string name="cloud_upload_delay_summary">"new photos synchronized to the delay time before cloud services millet
%s"</string>
<string name="color_for_all_icons">icon color</string>
<string name="color_for_all_icons_summary">the status bar icon color</string>
<string name="common">desktop</string>
<string name="config_folder_columns_count">folder number of icons per row</string>
<string name="config_folder_columns_count_summary">folder number of icons per row after opening: %s</string>
<string name="config_launcher_icons_size">desktop icons / folders size ratio</string>
<string name="config_launcher_icons_size_summary">desktop icons / folders size ratio: %s</string>
<string name="custom_build_prop">device properties</string>
<string name="custom_build_prop_board">board</string>
<string name="custom_build_prop_board_value">ro.product.board</string>
<string name="custom_build_prop_brand">brand</string>
<string name="custom_build_prop_brand_value">ro.product.brand</string>
<string name="custom_build_prop_device">device</string>
<string name="custom_build_prop_device_value">ro.product.device</string>
<string name="custom_build_prop_model">model</string>
<string name="custom_build_prop_model_value">ro.product.model</string>
<string name="custom_build_prop_name">name</string>
<string name="custom_build_prop_name_value">ro.product.name</string>
<string name="custom_build_prop_summary">custom settings build.prop parameters</string>
<string name="custom_carrier_label">custom operators tag</string>
<string name="custom_carrier_logo">operators tag</string>
<string name="custom_carrier_logo_summary">alternative operators use image identification tag</string>
<string name="default_carrier_label">leave blank to use the default carrier tag</string>
<string name="device">rotation</string>
<string name="dialog_color_picker">color picker</string>
<string name="disable_albumart_download">do not download cover</string>
<string name="disable_albumart_download_summary">prohibits automatically download album cover images</string>
<string name="disable_numberpicker_sound">touch sound disable dialpad</string>
<string name="disable_numberpicker_sound_summary">touch sound disable dialpad ( calculator, alarm clock and other tone )</string>
<string name="disable_safe_volume_warning">disabling safe volume warning</string>
<string name="disable_safe_volume_warning_summary">when using headphones to listen to music,disable security warning dialog box volume</string>
<string name="disable_scrolling_cache">scroll cache disabled</string>
<string name="disable_scrolling_cache_summary">"scroll cache disabled list
you might raise some fluency scrolling list"</string>
<string name="disable_sms_to_mms_conversion">allow long sms</string>
<string name="disable_sms_to_mms_conversion_summary">disable automatically converted to mms messages</string>
<string name="disable_volume_control_sound">disable beep sound sound</string>
<string name="disable_volume_control_sound_summary">beep sound sounds when adjusting the volume disabled</string>
<string name="double_click_menu_app">double-click the menu button</string>
<string name="double_click_menu_app_summary">double-click the menu key to start the selected application</string>
<string name="double_tap_menu_action">double-click the menu button behavior</string>
<string name="double_tap_menu_action_summary">%s</string>
<string name="enable_custom_build_prop">use custom property values</string>
<string name="enable_custom_build_prop_summary">"the following parameters will be modified on bootup
build.prop file will not be modified"</string>
<string name="extra_battery_info">additional battery information</string>
<string name="extra_battery_info_summary">add battery power settings information</string>
<string name="festival_update_server">recommended sms update server</string>
<string name="festival_update_server_summary">%s</string>
<string name="fix_screenshot_position">fixed " screenshots " position</string>
<string name="fix_screenshot_position_summary">fixed some screenshots options displacement situation. if you have the option to display normal position , please do not turn this option</string>
<string name="font_size">font size</string>
<string name="font_size_summary">set the status bar text size: %s</string>
<string name="framework">more settings</string>
<string name="framework_summary">more system settings</string>
<string name="gallery_old_videoplayer">using the system player to play video</string>
<string name="gallery_old_videoplayer_summary">miuivideoplayer.apk must be installed in / system / app folder</string>
<string name="headset_notification_icon">hide headset notification icons</string>
<string name="headset_notification_icon_summary">when headphones are plugged in headphones icon is displayed</string>
<string name="hide_alarm_icon">hide the clock icon</string>
<string name="hide_battery_icon">hide the battery icon</string>
<string name="hide_battery_icon_summary">whether to show the battery icon</string>
<string name="hide_carrier_label">hide operators tag</string>
<string name="hide_carrier_label_summary">whether operators tag</string>
<string name="hide_folders_label">hidden folder labels</string>
<string name="hide_folders_label_summary">only hide desktop folder text label</string>
<string name="hide_hotseats_bar">hide the navigation</string>
<string name="hide_hotseats_bar_summary">it allows you to hide desktop navigation bar to get more space arrangement applications</string>
<string name="hide_hotseats_label">hide navigation icon labels</string>
<string name="hide_hotseats_label_summary">only hide the navigation bar at the bottom of the desktop icon labels</string>
<string name="hide_icons_label">hide desktop icon labels</string>
<string name="hide_icons_label_summary">only hide desktop icons for all applications under the text label</string>
<string name="hide_launcher_apps_list">desktop application icon list</string>
<string name="hide_launcher_apps_summary">you can choose to want to hide the icon on the desktop program</string>
<string name="hide_launcher_apps_title">hide the selected icon</string>
<string name="hide_ongoing_ime_switcher">hide input method switcher</string>
<string name="hide_ongoing_ime_switcher_summary">whether to switch the input method notified when entering</string>
<string name="hide_roaming_icon">hide roaming icon</string>
<string name="holidays_selector_country">country holidays</string>
<string name="holidays_selector_country_belarus">belarus ( belarus)</string>
<string name="holidays_selector_country_czech">czech republic(czech republic)</string>
<string name="holidays_selector_country_kazakhstan">kazakhstan(kazakhstan()</string>
<string name="holidays_selector_country_original">default ( china )</string>
<string name="holidays_selector_country_poland">poland ( poland )</string>
<string name="holidays_selector_country_russia">russia(russia)</string>
<string name="holidays_selector_country_slovakia">slovakia ( slovakia )</string>
<string name="holidays_selector_country_summary">%s</string>
<string name="holidays_selector_country_turkmenistan">turkmenistan ( turkmenistan )</string>
<string name="holidays_selector_country_ukraine">ukraine(ukraine)</string>
<string name="holidays_update_server">holidays updated server</string>
<string name="holidays_update_server_summary">%s</string>
<string name="international_t9">t9 search add</string>
<string name="international_t9_summary">enabling contacts international t9 search</string>
<string name="key_menu">menu (menu)</string>
<string name="key_volume">volume keys</string>
<string name="launch_playback_screen">start the player interface</string>
<string name="launch_playback_screen_summary">click start to play music when pop pendant interface . by default, the player opens the main interface</string>
<string name="launcher">desktop</string>
<string name="launcher_font_size">desktop icons / folders text size</string>
<string name="launcher_font_size_summary">desktop icons / folders label text size : %s</string>
<string name="launcher_icons_color">select the icon / folder label color</string>
<string name="launcher_icons_color_summary">select the desktop icon / folder label text color</string>
<string name="launcher_summary">desktop -related settings</string>
<string name="local_yellowpage_database">local yellow pages database</string>
<string name="local_yellowpage_database_dialog">"china pages database will be cleared.
you need to restart the update t9 index data in the contacts settings.
you want to continue?"</string>
<string name="local_yellowpage_database_summary">yellow shield china from the server to update and increase contacts marked unknown function</string>
<string name="localized_measure_units">localization number of units</string>
<string name="localized_measure_units_summary">"• status bar : network speed (kb / s, mb / s)
• task manager: cleared, available memory (mb, gb)
• data flow : b, kb, mb, gb"</string>
<string name="lockscreen_rotations">enable lock screen rotation</string>
<string name="lockscreen_rotations_summary">allows lock screen rotation to landscape mode</string>
<string name="long_press_menu_action">press the menu key behavior</string>
<string name="long_press_menu_action_summary">%s</string>
<string name="long_press_track_skip">volume keys jump track</string>
<string name="long_press_track_skip_summary">when the screen is turned off long press the volume key to jump track</string>
<string name="menu_action_custom_app">start the custom applications</string>
<string name="menu_action_default">default</string>
<string name="menu_action_previous_app">the launch of an application</string>
<string name="menu_action_sleep">lock screen</string>
<string name="menu_action_torch">flashlight</string>
<string name="mitools_copyright">"any module modifications prohibited.
burgerz md, copyright © 2015, all rights reserved"</string>
<string name="miwarning_close">drop out</string>
<string name="miwarning_continue">carry on</string>
<string name="miwarning_message">"some models use this program may be no effect, or some features can not be used .
you want to continue?"</string>
<string name="miwarning_title">welcome to the program</string>
<string name="mms_unicode_stripping">normalization unicode</string>
<string name="mms_unicode_stripping_all">remove all unicode character</string>
<string name="mms_unicode_stripping_leave_intact">remains intact</string>
<string name="mms_unicode_stripping_non_encodable">unable to remove the encoded characters</string>
<string name="mms_unicode_stripping_summary">"will unicode character is converted to an ordinary character
mode: %s
( yet) does not work on some devices!"</string>
<string name="module_desc">"miui6hide icons , modify the label color
[click here to enter the settings take effect after restart]"</string>
<string name="module_desc_full">"miui6desktop toolbox
the desktop toolbox can hide desktop icons, labels , modify the icon size text color and other functions."</string>
<string name="module_name">desktop toolbox</string>
<string name="multiline_labels">multiple lines icon / folders tab</string>
<string name="multiline_labels_summary">multi-line desktop icons / folders tag</string>
<string name="national_roaming">domestic data roaming</string>
<string name="national_roaming_summary">but open domestic roaming data services</string>
<string name="navigation_bar">navigation bar</string>
<string name="navigation_bar_color">navigation bar color</string>
<string name="navigation_bar_color_summary">navigation bar background color</string>
<string name="navigation_bar_height">navigation bar height</string>
<string name="navigation_bar_height_landscape">the height of the navigation bar</string>
<string name="navigation_bar_height_summary">height : %s</string>
<string name="navigation_bar_override">override default</string>
<string name="navigation_bar_override_summary">navigation bar adjustment</string>
<string name="navigation_bar_width">navigation bar width</string>
<string name="network_speed_exp_statusbar">current network speed</string>
<string name="network_speed_exp_statusbar_summary">the status bar displays the current network speed</string>
<string name="none">(no)</string>
<string name="notif_reboot">reboot</string>
<string name="notif_reboot_required">restart for the changes to take effect</string>
<string name="notif_reboot_required_message">you need to restart to apply changes</string>
<string name="notif_reboot_required_title">need to restart</string>
<string name="notif_soft_reboot">soft reboot</string>
<string name="notif_torch_on">flashlight</string>
<string name="notification_bubble_apps">application list</string>
<string name="notifications">notice</string>
<string name="one_color_for_all_icons">all icons single color</string>
<string name="one_color_for_all_icons_summary">let all the icons on the status bar using a single color</string>
<string name="own_carrier_logo">select custom logo</string>
<string name="own_carrier_logo_2">select custom identified logo</string>
<string name="own_carrier_logo_summary">%s</string>
<string name="power">about</string>
<string name="power_cancel">cancel</string>
<string name="power_reboot">reboot</string>
<string name="power_reboot_bootloader">reboot into the brush machine mode (fastboot)</string>
<string name="power_reboot_hot">quick restart</string>
<string name="power_reboot_normal">normal restart</string>
<string name="power_reboot_options">restart menu</string>
<string name="power_reboot_recovery">reboot into recovery mode (recovery)</string>
<string name="power_reboot_switch_system">switching system ( millet phone only)</string>
<string name="power_reboot_system_1">reboot the system</string>
<string name="power_reboot_system_2">reboot the system two</string>
<string name="preference_app_picker_search">search applications</string>
<string name="press_color_to_apply">tap the color to apply</string>
<string name="quicksearchbox_marketplace">search market</string>
<string name="quicksearchbox_marketplace_summary">"search for the following markets :
%s"</string>
<string name="screenshot_delay">screenshot delay ( ms)</string>
<string name="select_carrier_logo">select identity</string>
<string name="select_carrier_logo_2">select identify two</string>
<string name="select_carrier_logo_summary">%s</string>
<string name="set_launcher_icons_color">select the icon / folder label color</string>
<string name="set_launcher_icons_color_summary">use custom icons / folders label color</string>
<string name="show_battery_text">icon appears next to the text</string>
<string name="show_battery_text_summary">display battery percentage</string>
<string name="show_navigation_bar">show navigation bar</string>
<string name="show_navigation_bar_summary">within the display screen buttons (nexus style )</string>
<string name="show_notification_bubble">display notification bubble</string>
<string name="show_notification_bubble_summary">bubble notification is displayed on the application's icon</string>
<string name="signal_bars_color">signal color</string>
<string name="signal_bars_color_2">signal color two</string>
<string name="signal_bars_color_summary">setting the mobile network signal indicator color</string>
<string name="signal_bars_color_summary_2">setting the mobile network signal indicator color ( card b)</string>
<string name="sound">voice</string>
<string name="sound_summary">voice -related settings</string>
<string name="statusbar">status bar</string>
<string name="statusbar_background_color">background color</string>
<string name="statusbar_background_color_summary">the status bar background color</string>
<string name="statusbar_common">general options</string>
<string name="statusbar_set_background_color">change the background color</string>
<string name="statusbar_set_background_color_summary">allows background color modify the status bar</string>
<string name="statusbar_summary">modify status bar</string>
<string name="statusbar_text_family">font style</string>
<string name="statusbar_text_family_summary">select the status bar font style : %s</string>
<string name="statusbar_text_style">font style</string>
<string name="statusbar_text_style_summary">select the status bar font style: %s</string>
<string name="supermarket_disable_autoupdates_check">disable check for updates</string>
<string name="supermarket_disable_autoupdates_check_summary">disable the automatic check for updates</string>
<string name="supermarket_reverse_tabs_order">reverse tab order</string>
<string name="supermarket_reverse_tabs_order_summary">tags will modify order: management , classification , ranking , fine</string>
<string name="swap_long_press_skip_keys">switching button</string>
<string name="swap_long_press_skip_keys_summary">when switching tone skip track</string>
<string name="take_screenshot">screenshots</string>
<string name="text_large">large</string>
<string name="text_medium">in</string>
<string name="text_small">small</string>
<string name="themes_replace_lunar_dates">replace lunar date</string>
<string name="themes_replace_lunar_dates_summary">try to find topic lunar date and replaced by the gregorian calendar ( lock screen )</string>
<string name="themes_reverse_tabs_order">reverse tab order</string>
<string name="themes_reverse_tabs_order_summary">tags will modify order: i , classification , ranking , fine</string>
<string name="time_10_min">10 minutes</string>
<string name="time_1_hour">1 hour</string>
<string name="time_1_min">1 min (default )</string>
<string name="time_30_min">30 minute</string>
<string name="time_30_sec">30 second</string>
<string name="time_5_min">5 minute</string>
<string name="typeface_family_condensed">compact</string>
<string name="typeface_family_light">lighter</string>
<string name="typeface_family_regular">usually</string>
<string name="typeface_family_thin">fine</string>
<string name="typeface_style_bold">bold face</string>
<string name="typeface_style_italic">italic type</string>
<string name="typeface_style_normal">general</string>
<string name="units_b">b</string>
<string name="units_gb">gb</string>
<string name="units_kb">kb</string>
<string name="units_kbs">kb/s</string>
<string name="units_mb">mb</string>
<string name="units_mbs">mb/s</string>
<string name="units_s">s</string>
<string name="unlink_notification_volume">volume settings are not synchronized</string>
<string name="unlink_notification_volume_summary">separate ringtones & amp; notice the volume settings</string>
<string name="updater_disable_autoupdates_check">disable check for updates</string>
<string name="updater_disable_autoupdates_check_summary">disable the automatic check for updates</string>
<string name="updater_english_changelog">display english update log</string>
<string name="updater_english_changelog_summary">english forced display update log</string>
<string name="use_own_carrier_logo">custom operator identification</string>
<string name="use_own_carrier_logo_summary">you can choose your own carrier logo</string>
<string name="vol_key_cursor">volume keys cursor control</string>
<string name="vol_key_cursor_reverse">switching button</string>
<string name="vol_key_cursor_reverse_summary">exchange volume keys control the cursor when</string>
<string name="vol_key_cursor_summary">use the volume keys to control the cursor input</string>
<string name="volume_notification_description">notice</string>
<string name="volume_ring_description">ring</string>
<string name="volume_step">volume step</string>
<string name="volume_steps_alarm">alarm volume</string>
<string name="volume_steps_bluetooth">bluetooth volume</string>
<string name="volume_steps_music">music volume</string>
<string name="volume_steps_notification">notification volume</string>
<string name="volume_steps_ring">ringer volume</string>
<string name="volume_steps_system">media volume</string>
<string name="volume_steps_voice_call">call volume</string>
<string name="preference_app_picker_none">(no)</string>
<string name="show_clock_date">show status bar date</string>
<string name="show_clock_date_summary">in the status bar next to the clock display date</string>
<string name="holidays_selector_country_german">germany</string>
<string name="statusbar_title">status bar</string>
</resources>
Obviously, you have an error at strings.xml at line #324
This is that line:
<string name="unlink_notification_volume_summary">separate ringtones & amp; notice the volume settings</string>
you have an unnecessary space between & and amp;.

Android no set default values

I followed all the instructions for setting default preference values step by step but does not work.
1º I set the default values:
<PreferenceCategory android:title="#string/settings_game" >
<ListPreference
android:defaultValue="1.5"
android:entries="#array/intervale_count"
android:entryValues="#array/intervale_count_values"
android:key="interval"
android:title="#string/interval" />
<ListPreference
android:defaultValue="#string/mode_normal"
android:entries="#array/mode_game"
android:entryValues="#array/mode_game_values"
android:key="mode"
android:title="#string/mode" />
</PreferenceCategory>
<PreferenceCategory android:title="#string/settings_sound" >
<ListPreference
android:defaultValue="#string/stone"
android:entries="#array/time_sounds"
android:entryValues="#array/time_sounds_values"
android:key="time_sounds"
android:title="#string/sounds_stones" />
<ListPreference
android:defaultValue="#string/vuvucela"
android:entries="#array/gong_sounds"
android:entryValues="#array/gong_sounds_values"
android:key="gong_sounds"
android:title="#string/sounds_gong" />
</PreferenceCategory>
2º I get the preferences in my MainActivity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
}
But when I open the preference view no preferences are selected, the strings of I declare in the android:defaultValue is the SAME as one of the options Ihave in the array of data in android:entries.
Note: I try to change to true the boolean in
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
but that still does not work.
I've also tried to uninstall and delete the data of the app but that still does not work.
Edit: the array values
<string-array name="intervale_count">
<item>1</item>
<item>1.3</item>
<item>1.5</item>
<item>1.7</item>
<item>2</item>
</string-array>
<string-array name="intervale_count_values">
<item>1000</item>
<item>1300</item>
<item>1500</item>
<item>1700</item>
<item>2000</item>
</string-array>
<string-array name="mode_game">
<item>#string/mode_normal</item>
<item>#string/mode_extension</item>
<item>#string/mode_infinite</item>
</string-array>
<string-array name="mode_game_values">
<item>100</item>
<item>50</item>
<item>1000</item>
</string-array>
<string-array name="time_sounds">
<item>#string/alan</item>
<item>#string/cash_reg</item>
<item>#string/censure</item>
<item>#string/crow</item>
<item>#string/doh</item>
<item>#string/fb_noti</item>
<item>#string/achievement</item>
<item>#string/metal_gear</item>
<item>#string/duck</item>
<item>#string/pan</item>
<item>#string/drum</item>
<item>#string/stone</item>
</string-array>
<string-array name="time_sounds_values">
<item>2131099648</item> <!-- Alan -->
<item>2131099649</item> <!-- Registradora -->
<item>2131099650</item> <!-- Censura -->
<item>2131099651</item> <!-- Cuervo -->
<item>2131099652</item> <!-- DOh -->
<item>2131099653</item> <!-- FB -->
<item>2131099655</item> <!-- logro -->
<item>2131099656</item> <!--metal gear -->
<item>2131099657</item> <!-- pato -->
<item>2131099658</item><!-- sarten -->
<item>2131099660</item> <!-- tambor -->
<item>2131099659</item><!-- stone -->
</string-array>
<string-array name="gong_sounds">
<item>#string/gong</item>
<item>#string/vuvucela</item>
</string-array>
<string-array name="gong_sounds_values">
<item>2131099654</item> <!-- Gong -->
<item>2131099661</item> <!-- Vuvucela -->
</string-array>
The defaultValue attribute for a ListPreference needs to be a value, not the entry text. In other words, it should be an element in the array you pass to android:entryValues, not an element in the array you pass to android:entries.
For example, your gong sounds preference should use android:defaultValue="2131099661" instead of android:defaultValue="#string/vuvucela"
If it doesn't work, try to wipe the app data from the emulator/device and then reinstall the app. After I did that in my project and followed Tanis hints, it worked like a charm.

Activity using prefs.xml <ListPreference> for Colour changing crashes when started

I'm trying to change background and/or text colours of my Main activity with a SettingsActivity which is opened with the settings button and pretty much only calls addPreferencesFromResource(R.xml.preferences).
This is the SettingsActivity:
public class SettingsActivity extends PreferenceActivity {
#SuppressWarnings("deprecation")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
I have string-arrays in an arrays.xml text_color_entries holding names, ..._values holding #android:color/... like values and an #rrggbb value:
<resources>
<string-array name="text_size_entries">
<item>16 pt</item>
<item>18 pt</item>
<item>20 pt</item>
<item>22 pt</item>
<item>24 pt</item>
<item>26 pt</item>
</string-array>
<string-array name="text_size_values">
<item>16</item>
<item>18</item>
<item>20</item>
<item>22</item>
<item>24</item>
<item>26</item>
</string-array>
<string-array name="background_colour_entries">
<item>Original</item>
<item>White</item>
<item>Light Orange</item>
<item>Dark Orange</item>
<item>Light Green</item>
<item>Dark Green</item>
<item>Light Red</item>
<item>Dark Red</item>
<item>Bright Blue</item>
<item>Light Blue</item>
<item>Dark Blue</item>
<item>Black</item>
</string-array>
<string-array name="background_colour_values">
<item>#0030ff</item>
<item>#android:color/background_light</item>
<item>#android:color/holo_orange_dark</item>
<item>#android:color/holo_green_light</item>
<item>#android:color/holo_green_dark</item>
<item>#android:color/holo_red_light</item>
<item>#android:color/holo_red_dark</item>
<item>#android:color/holo_blue_bright</item>
<item>#android:color/holo_blue_light</item>
<item>#android:color/holo_blue_dark</item>
<item>#android:color/background_dark</item>
</string-array>
<string-array name="text_colour_entries">
<item>Original(Light Orange)</item>
<item>White</item>
<item>Light Orange</item>
<item>Dark Orange</item>
<item>Light Green</item>
<item>Dark Green</item>
<item>Light Red</item>
<item>Dark Red</item>
<item>Bright Blue</item>
<item>Light Blue</item>
<item>Dark Blue</item>
<item>Black</item>
</string-array>
<string-array name="text_colour_values">
<item>#android:color/holo_orange_light</item>
<item>#android:color/background_light</item>
<item>#android:color/holo_orange_dark</item>
<item>#android:color/holo_green_light</item>
<item>#android:color/holo_green_dark</item>
<item>#android:color/holo_red_light</item>
<item>#android:color/holo_red_dark</item>
<item>#android:color/holo_blue_bright</item>
<item>#android:color/holo_blue_light</item>
<item>#android:color/holo_blue_dark</item>
<item>#android:color/background_dark</item>
</string-array>
</resources>
And a preferences.xml holding a CheckboxPreference and 3 ListPreferences:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="Settings">
<CheckBoxPreference
android:key="pref_text_bold"
android:title="Make Text Bold"
android:summary="Makes the note text bold"
android:defaultValue="false"/>
<ListPreference
android:key="pref_text_size"
android:title="Text Size"
android:summary="Pick the text size"
android:entries="#array/text_size_entries"
android:entryValues="#array/text_size_values"
android:defaultValue="16"/>
<!-- Works if I erase/comment out anything below here -->
<ListPreference
android:key="pref_background_colour"
android:title="Background colour"
android:summary="Choose the background colour of the app"
android:entries="#array/background_colour_entries"
android:entryValues="#array/background_colour_values"
android:defaultValue="#0030ff"/>
<ListPreference
android:key="pref_text_colour"
android:title="Text colour"
android:summary="Choose the colour of your text"
android:entries="#array/text_colour_entries"
android:entryValues="#array/text_colour_values"
android:defaultValue="#android:color/holo_orange_light"/>
</PreferenceScreen>
When I only had the CheckboxPreference and the first ListPreference in there, it worked perfectly fine. It also works fine when I comment out the other 2 Listpreferences.
But as soon I have at least one of the other ListPreferences in the app it crashes as soon as I try to open the settings activity.
I haven't implemented those other two preference lists in my MainActivity yet, I wanted to get the layout to work first.
Bonus question:
How exactly should I implement the background and edittext-text color changing, is it even possible using the ressource links, and can I use a
<color>
array instead?
Thanks for your time, I hope that's not too much stuff up there.
Greetings,
Marlon
EDIT: Tried to debug, didn't really help me. Went through some deeper classes I don't know about and then crashed.
Also, LogCat says there is a NullPointerException somewhere, but doesn't give me a concrete position in my code, only points to
ListPreference.findiIndexOfValue(Listpreference.java:223)
Edit 2: esme-louise pointed out my value arrays were missing a line. I changed that, it unfortunately didn't solve the problem.
Edit 3: color.xml now looks like Audi describes, ListPrefrence now has
android:entries="#array/background_colors"
android:entryValues="#array/background_colors"
but still crashes the app when starting the settings activity.
Edit 4:
I now put notesEditText.setTextColor(Color.parseColor(sharedPreferences.getString
("pref_background_colour", "#color/OriginalBackground")));into the method called when returning from the settings, worrying about that when the Layout thing works.
The LogCat:
02-08 16:07:25.395 23749-23749/com.regenhardt.savingstate E/﹕ appName=com.regenhardt.savingstate, acAppName=/system/bin/surfaceflinger
02-08 16:07:25.395 23749-23749/com.regenhardt.savingstate E/﹕ 0
02-08 16:07:29.357 23749-23749/com.regenhardt.savingstate E/TextView﹕ get resource from application failed.
**This one comes many, many times here and before the surfaceflinger thing, practically all the time it's running. I deleted a TextView from the layout and commented it out of the java code; wasn't anything dynamic, just a title**
02-08 16:07:30.932 23749-23749/com.regenhardt.savingstate E/TextView﹕ get resource from application failed.
02-08 16:07:30.952 23749-23749/com.regenhardt.savingstate E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.regenhardt.savingstate, PID: 23749
java.lang.NullPointerException
at android.preference.ListPreference.findIndexOfValue(ListPreference.java:223)
**From here on stuff I couldn't even begin to understand so didn't bother digging into android**
at android.preference.ListPreference.getValueIndex(ListPreference.java:232)
at android.preference.ListPreference.getEntry(ListPreference.java:210)
at android.preference.ListPreference.getSummary(ListPreference.java:156)
at android.preference.Preference.onBindView(Preference.java:534)
at android.preference.Preference.getView(Preference.java:472)
at android.preference.PreferenceGroupAdapter.getView(PreferenceGroupAdapter.java:221)
at android.widget.AbsListView.obtainView(AbsListView.java:2338)
at android.widget.ListView.makeAndAddView(ListView.java:1812)
at android.widget.ListView.fillDown(ListView.java:698)
at android.widget.ListView.fillFromTop(ListView.java:759)
at android.widget.ListView.layoutChildren(ListView.java:1645)
at android.widget.AbsListView.onLayout(AbsListView.java:2149)
at android.view.View.layout(View.java:15125)
at android.view.ViewGroup.layout(ViewGroup.java:4862)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1888)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1742)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1651)
at android.view.View.layout(View.java:15125)
at android.view.ViewGroup.layout(ViewGroup.java:4862)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1888)
at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1877)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1653)
at android.view.View.layout(View.java:15125)
at android.view.ViewGroup.layout(ViewGroup.java:4862)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1888)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1742)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1651)
at android.view.View.layout(View.java:15125)
at android.view.ViewGroup.layout(ViewGroup.java:4862)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:515)
at android.widget.FrameLayout.onLayout(FrameLayout.java:450)
at android.view.View.layout(View.java:15125)
at android.view.ViewGroup.layout(ViewGroup.java:4862)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1888)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1742)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1651)
at android.view.View.layout(View.java:15125)
at android.view.ViewGroup.layout(ViewGroup.java:4862)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:515)
at android.widget.FrameLayout.onLayout(FrameLayout.java:450)
at android.view.View.layout(View.java:15125)
at android.view.ViewGroup.layout(ViewGroup.java:4862)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2317)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2023)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1189)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6223)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:788)
at android.view.Choreographer.doCallbacks(Choreographer.java:591)
at android.view.Choreographer.doFrame(Choreographer.java:560)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:774)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
at dalvik.system.NativeStart.main(Native Method)
Try using a color array instead of a string array. It is something like this
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="black">#000000</color>
<color name="white">#FFFFFF</color>
</resources>
Add this to your strings.xml
<string-array name="backgroud_entries">
<item>Black</item>
<item>White</item>
</string-array>
<string-array name="background_entry_values">
<item>#color/black</item>
<item>#color/white</item>
</string-array>
Modify your ListPreference like this
<ListPreference
android:key="pref_background_colour"
android:title="Background colour"
android:summary="Choose the background colour of the app"
android:entries="#array/background_entries"
android:entryValues="#array/background_entry_values"
android:defaultValue="#0030ff"/>

Incorrect values when I select a radioButton in ListPreference

I have a Preference activity which uses a List Preferences as defined by my XML file:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="sync">
<ListPreference
android:key="key_sync_period"
android:title="Sync"
android:summary="%s"
android:dialogTitle="Sync frequency"
android:entries="#array/sync_period_entries"
android:entryValues="#array/sync_period_values"
android:defaultValue="1800" />
</PreferenceCategory>
</PreferenceScreen>
arrays.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="sync_period_entries">
<item>15 min</item>
<item>30 min</item>
<item>45 min</item>
<item>1 hour</item>
</string-array>
<string-array name="sync_period_values">
<item>900</item>
<item>1800</item>
<item>2700</item>
<item>3600</item>
</string-array>
</resources>
When I start my app, change this setting, I see the following:
the app writes to a defaultSharedPreference file value = 1800
I change it to "15 min" and see value = 900 - ok, all right
I change it to "45 min" and see value = 60 - ???
I change it to "1 hour" and see value = 180 - ???????
I change again it to "30 min" and see value = 1800
I change it to "1 hour" and see value = 180 - why?
Why do I see these values (60, 180)? Where did they come from?
Update 1:
if (key.equals("key_sync_period"))
{
ListPreference syncPref = (ListPreference) findPreference(key);
syncPref.setSummary(syncPref.getEntry());
long seconds = Long.valueOf(sharedPreferences.getString(key, "1800"));
}
The system writes defaultSharedPreferences. I see preference file from ddms and see that the system written wrong value.
The problem was in the Idea 12CE, I deleted the project and imported it again... and problem was solved.

AT&T XML speech recognition

I have to recognize some alternative rules, but I don't know how to do a mutual exclusion.
For example, if I want to recognize "play", "stop", or "set 1", "set 2", how can I do? I tried something like this, but it doesn't recognize when I don't need the number (for example, "start 2" is correctly recognized, but trivially I don't want to).
<grammar version="1.0" tag-format="semantics/1.0" xml:lang="en-US" root="main">
<rule id="main">
<ruleref uri="#actions"/>
<ruleref uri="#numbers"/>
</rule>
<rule id="actions">
<item repeat="0-1">
<one-of>
<item>play</item>
<item>stop</item>
<item>set</item>
</one-of>
</item>
</rule>
<rule id="numbers">
<item repeat="0-1">
<one-of>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
<item>6</item>
<item>7</item>
<item>8</item>
<item>9</item>
</one-of>
</item>
</rule>
</grammar>
Simply I found out that if I put
<item>play <ruleref special="GARBAGE"/></item>
<item>stop <ruleref special="GARBAGE"/></item>
<item>set <ruleref special="GARBAGE"/><ruleref uri="#numbers"/></item>
calling the id reference after set will take just "set 1", "set 2", but doesn't accept "start 1" because there isn't the reference after the name.

Categories

Resources