Search in sources :

Example 81 with Preference

use of android.preference.Preference in project xabber-android by redsolution.

the class DebugSettingsFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preference_debug);
    PreferenceScreen preferenceScreen = getPreferenceScreen();
    preferenceScreen.removePreference(preferenceScreen.findPreference(getString(R.string.debug_log_key)));
    preferenceScreen.removePreference(preferenceScreen.findPreference(getString(R.string.cache_clear_key)));
    preferenceScreen.removePreference(preferenceScreen.findPreference(getString(R.string.debug_connection_errors_key)));
    Preference prefDownloadArchive = preferenceScreen.findPreference(getString(R.string.debug_download_all_messages_key));
    prefDownloadArchive.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            startMessageArchiveDownload();
            return true;
        }
    });
    if (!BuildConfig.DEBUG) {
        preferenceScreen.removePreference(prefDownloadArchive);
    }
    if (!SettingsManager.isCrashReportsSupported()) {
        preferenceScreen.removePreference(preferenceScreen.findPreference(getString(R.string.debug_crash_reports_key)));
    }
    PreferenceSummaryHelperActivity.updateSummary(preferenceScreen);
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) Preference(android.preference.Preference)

Example 82 with Preference

use of android.preference.Preference in project xabber-android by redsolution.

the class PreferencesFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preference_editor);
    Preference about = getPreferenceScreen().findPreference(getString(R.string.preference_about_key));
    about.setSummary(getString(R.string.application_title_full) + "\n" + mListener.getVersionName());
    PreferenceSummaryHelperActivity.updateSummary(getPreferenceScreen());
}
Also used : Preference(android.preference.Preference) XMPPListPreference(com.xabber.android.ui.widget.XMPPListPreference)

Example 83 with Preference

use of android.preference.Preference in project MyJapanese by 54wall.

the class SettingFragment method initPreference.

private void initPreference() {
    mTTSListPreference = (ListPreference) getPreferenceManager().findPreference("setting_tts");
    mTTSListPreference.setEntries(R.array.tts_entries);
    mTTSListPreference.setEntryValues(R.array.tts_values);
    mTTSListPreference.setValue(tts_type);
    mTTSListPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            SharedPreferenceManager.getInstance().putString(Constants.TTS_TYPE, (String) newValue);
            JpTTSUtils.getInstance().updateTtsType();
            RxBus.getDefault().post(new EventContainer(EventContainer.TYPE_SETTING, new SettingEvent(R.string.setting_effect)));
            return true;
        }
    });
    mThemesListPreference = (ListPreference) getPreferenceManager().findPreference("setting_theme");
    mThemesListPreference.setEntries(R.array.themes_entries);
    mThemesListPreference.setEntryValues(R.array.themes_values);
    mThemesListPreference.setValue(mode_theme);
    mThemesListPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            SharedPreferenceManager.getInstance().putString(Constants.MODE_THEME, (String) newValue);
            RxBus.getDefault().post(new EventContainer(EventContainer.TYPE_SETTING, new SettingEvent(R.string.reboot_to_take_effect)));
            return true;
        }
    });
    mConnectCheckBoxPreference = (CheckBoxPreference) getPreferenceManager().findPreference("setting_wifi");
    mConnectCheckBoxPreference.setChecked(allow_connect);
    mConnectCheckBoxPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Log.i(TAG, "onPreferenceChange: " + newValue);
            SharedPreferenceManager.getInstance().putBoolean(Constants.ALLOW_CONNECT_WITHOUT_WIFI, (Boolean) newValue);
            RxBus.getDefault().post(new EventContainer(EventContainer.TYPE_SETTING, new SettingEvent(R.string.setting_effect)));
            return true;
        }
    });
}
Also used : CheckBoxPreference(android.preference.CheckBoxPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) EventContainer(pri.weiqiang.myjapanese.rxbus.event.EventContainer) SettingEvent(pri.weiqiang.myjapanese.rxbus.event.SettingEvent)

Example 84 with Preference

use of android.preference.Preference in project aware-client by denzilferreira.

the class Aware_Client method onResume.

@Override
protected void onResume() {
    super.onResume();
    permissions_ok = true;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        for (String p : REQUIRED_PERMISSIONS) {
            if (PermissionChecker.checkSelfPermission(this, p) != PermissionChecker.PERMISSION_GRANTED) {
                permissions_ok = false;
                break;
            }
        }
    }
    if (!permissions_ok) {
        Log.d(Aware.TAG, "Requesting permissions...");
        Intent permissionsHandler = new Intent(this, PermissionsHandler.class);
        permissionsHandler.putStringArrayListExtra(PermissionsHandler.EXTRA_REQUIRED_PERMISSIONS, REQUIRED_PERMISSIONS);
        permissionsHandler.putExtra(PermissionsHandler.EXTRA_REDIRECT_ACTIVITY, getPackageName() + "/" + getClass().getName());
        permissionsHandler.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(permissionsHandler);
    } else {
        if (prefs.getAll().isEmpty() && Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID).length() == 0) {
            PreferenceManager.setDefaultValues(getApplicationContext(), "com.aware.phone", Context.MODE_PRIVATE, com.aware.R.xml.aware_preferences, true);
            prefs.edit().commit();
        } else {
            PreferenceManager.setDefaultValues(getApplicationContext(), "com.aware.phone", Context.MODE_PRIVATE, R.xml.aware_preferences, false);
        }
        Map<String, ?> defaults = prefs.getAll();
        for (Map.Entry<String, ?> entry : defaults.entrySet()) {
            if (Aware.getSetting(getApplicationContext(), entry.getKey(), "com.aware.phone").length() == 0) {
                // default AWARE settings
                Aware.setSetting(getApplicationContext(), entry.getKey(), entry.getValue(), "com.aware.phone");
            }
        }
        if (Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID).length() == 0) {
            UUID uuid = UUID.randomUUID();
            Aware.setSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID, uuid.toString(), "com.aware.phone");
        }
        if (Aware.getSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_SERVER).length() == 0) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_SERVER, "https://api.awareframework.com/index.php");
        }
        Set<String> keys = optionalSensors.keySet();
        for (String optionalSensor : keys) {
            Preference pref = findPreference(optionalSensor);
            PreferenceGroup parent = getPreferenceParent(pref);
            if (pref.getKey().equalsIgnoreCase(optionalSensor) && !listSensorType.containsKey(optionalSensors.get(optionalSensor)))
                parent.setEnabled(false);
        }
        try {
            PackageInfo awareInfo = getApplicationContext().getPackageManager().getPackageInfo(getApplicationContext().getPackageName(), PackageManager.GET_ACTIVITIES);
            Aware.setSetting(getApplicationContext(), Aware_Preferences.AWARE_VERSION, awareInfo.versionName);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        // Check if AWARE is active on the accessibility services. Android Wear doesn't support accessibility services (no API yet...)
        if (!Aware.is_watch(this)) {
            Applications.isAccessibilityServiceActive(this);
        }
        // Check if AWARE is allowed to run on Doze
        Aware.isBatteryOptimizationIgnored(this, getPackageName());
        prefs.registerOnSharedPreferenceChangeListener(this);
        // use all cores available to process UI faster
        new SettingsSync().executeOnExecutor(// use all cores available to process UI faster
        AsyncTask.THREAD_POOL_EXECUTOR, findPreference(Aware_Preferences.DEVICE_ID), findPreference(Aware_Preferences.DEVICE_LABEL), findPreference(Aware_Preferences.AWARE_VERSION), findPreference(Aware_Preferences.STATUS_ACCELEROMETER), findPreference(Aware_Preferences.STATUS_APPLICATIONS), findPreference(Aware_Preferences.STATUS_BAROMETER), findPreference(Aware_Preferences.STATUS_BATTERY), findPreference(Aware_Preferences.STATUS_BLUETOOTH), findPreference(Aware_Preferences.STATUS_CALLS), findPreference(Aware_Preferences.STATUS_COMMUNICATION_EVENTS), findPreference(Aware_Preferences.STATUS_CRASHES), findPreference(Aware_Preferences.STATUS_ESM), findPreference(Aware_Preferences.STATUS_GRAVITY), findPreference(Aware_Preferences.STATUS_GYROSCOPE), findPreference(Aware_Preferences.STATUS_INSTALLATIONS), findPreference(Aware_Preferences.STATUS_KEYBOARD), findPreference(Aware_Preferences.STATUS_LIGHT), findPreference(Aware_Preferences.STATUS_LINEAR_ACCELEROMETER), findPreference(Aware_Preferences.STATUS_LOCATION_GPS), findPreference(Aware_Preferences.STATUS_LOCATION_NETWORK), findPreference(Aware_Preferences.STATUS_LOCATION_PASSIVE), findPreference(Aware_Preferences.STATUS_MAGNETOMETER), findPreference(Aware_Preferences.STATUS_MESSAGES), findPreference(Aware_Preferences.STATUS_MQTT), findPreference(Aware_Preferences.STATUS_NETWORK_EVENTS), findPreference(Aware_Preferences.STATUS_NETWORK_TRAFFIC), findPreference(Aware_Preferences.STATUS_NOTIFICATIONS), findPreference(Aware_Preferences.STATUS_PROCESSOR), findPreference(Aware_Preferences.STATUS_PROXIMITY), findPreference(Aware_Preferences.STATUS_ROTATION), findPreference(Aware_Preferences.STATUS_SCREEN), findPreference(Aware_Preferences.STATUS_SIGNIFICANT_MOTION), findPreference(Aware_Preferences.STATUS_TEMPERATURE), findPreference(Aware_Preferences.STATUS_TELEPHONY), findPreference(Aware_Preferences.STATUS_TIMEZONE), findPreference(Aware_Preferences.STATUS_WIFI), findPreference(Aware_Preferences.STATUS_WEBSERVICE), findPreference(Aware_Preferences.MQTT_SERVER), findPreference(Aware_Preferences.MQTT_PORT), findPreference(Aware_Preferences.MQTT_USERNAME), findPreference(Aware_Preferences.MQTT_PASSWORD), findPreference(Aware_Preferences.MQTT_KEEP_ALIVE), findPreference(Aware_Preferences.MQTT_QOS), findPreference(Aware_Preferences.WEBSERVICE_SERVER), findPreference(Aware_Preferences.FREQUENCY_WEBSERVICE), findPreference(Aware_Preferences.FREQUENCY_CLEAN_OLD_DATA), findPreference(Aware_Preferences.WEBSERVICE_CHARGING), findPreference(Aware_Preferences.WEBSERVICE_SILENT), findPreference(Aware_Preferences.WEBSERVICE_WIFI_ONLY), findPreference(Aware_Preferences.WEBSERVICE_FALLBACK_NETWORK), findPreference(Aware_Preferences.REMIND_TO_CHARGE), findPreference(Aware_Preferences.WEBSERVICE_SIMPLE), findPreference(Aware_Preferences.WEBSERVICE_REMOVE_DATA), findPreference(Aware_Preferences.DEBUG_DB_SLOW), findPreference(Aware_Preferences.FOREGROUND_PRIORITY), findPreference(Aware_Preferences.STATUS_TOUCH));
    }
}
Also used : PackageInfo(android.content.pm.PackageInfo) Intent(android.content.Intent) PackageManager(android.content.pm.PackageManager) EditTextPreference(android.preference.EditTextPreference) ListPreference(android.preference.ListPreference) CheckBoxPreference(android.preference.CheckBoxPreference) Preference(android.preference.Preference) PreferenceGroup(android.preference.PreferenceGroup) UUID(java.util.UUID) Map(java.util.Map)

Example 85 with Preference

use of android.preference.Preference in project qksms by moezbhatti.

the class SettingsFragment method removePreference.

/**
 * Removes a preference from a given category
 */
private void removePreference(String key, String category) {
    Preference pref = findPreference(key);
    PreferenceCategory cat = (PreferenceCategory) findPreference(category);
    if (pref != null && cat != null) {
        cat.removePreference(pref);
    }
}
Also used : EditTextPreference(android.preference.EditTextPreference) ListPreference(android.preference.ListPreference) QKPreference(com.moez.QKSMS.enums.QKPreference) CheckBoxPreference(android.preference.CheckBoxPreference) Preference(android.preference.Preference) PreferenceCategory(android.preference.PreferenceCategory)

Aggregations

Preference (android.preference.Preference)183 CheckBoxPreference (android.preference.CheckBoxPreference)54 ListPreference (android.preference.ListPreference)54 PreferenceScreen (android.preference.PreferenceScreen)37 Intent (android.content.Intent)33 EditTextPreference (android.preference.EditTextPreference)29 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)23 PreferenceCategory (android.preference.PreferenceCategory)23 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)21 SharedPreferences (android.content.SharedPreferences)19 ChromeSwitchPreference (org.chromium.chrome.browser.preferences.ChromeSwitchPreference)16 PreferenceGroup (android.preference.PreferenceGroup)15 Test (org.junit.Test)15 Uri (android.net.Uri)12 Bundle (android.os.Bundle)12 ArrayList (java.util.ArrayList)11 Resources (android.content.res.Resources)10 SwitchPreference (android.preference.SwitchPreference)10 View (android.view.View)10 ChromeBasePreference (org.chromium.chrome.browser.preferences.ChromeBasePreference)10