Search in sources :

Example 41 with ListPreference

use of android.support.v7.preference.ListPreference in project Remindy by abicelis.

the class SettingsFragment method onCreatePreferencesFix.

@Override
public void onCreatePreferencesFix(@Nullable Bundle savedInstanceState, String rootKey) {
    addPreferencesFromResource(R.xml.remindy_settings);
    final Context packageContext = getActivity().getApplicationContext();
    mManagePlaces = findPreference(getResources().getString(R.string.settings_manage_places_key));
    mManagePlaces.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            Intent goToPlaceListActivity = new Intent(packageContext, PlaceListActivity.class);
            startActivity(goToPlaceListActivity);
            //TODO: Yes, this is a dirty hack, someday to be fixed
            ((SettingsActivity) getActivity()).mForceHomeRefresh = true;
            return true;
        }
    });
    mDateFormat = (ListPreference) findPreference(getResources().getString(R.string.settings_date_format_key));
    mDateFormat.setEntries(getDateFormatEntries());
    mTimeFormat = (ListPreference) findPreference(getResources().getString(R.string.settings_time_format_key));
    mTriggerMinutesBeforeNotification = (ListPreference) findPreference(getResources().getString(R.string.settings_trigger_minutes_before_notification_key));
    mTriggerMinutesBeforeNotification.setEntries(getTriggerMinutesBeforeNotificationEntries());
    mTriggerMinutesBeforeNotification.setEntryValues(getTriggerMinutesBeforeNotificationEntryValues());
    //        mShowLocationBasedReminderInNewTab = (SwitchPreference) findPreference(getResources().getString(R.string.settings_show_location_based_reminder_in_new_tab_key));
    //        handleShowLocationBasedReminderInNewTabPreferenceChange(getShowLocationBasedReminderInNewTabValue());
    //        mShowLocationBasedReminderInNewTab.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
    //            @Override
    //            public boolean onPreferenceChange(Preference preference, Object newValue) {
    //                handleShowLocationBasedReminderInNewTabPreferenceChange((boolean) newValue);
    //                return true;
    //            }
    //        });
    mBackup = findPreference(getResources().getString(R.string.settings_backup_key));
    mRestore = findPreference(getResources().getString(R.string.settings_restore_key));
    mBackup.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            // Check for external storage permissions
            String[] nonGrantedPermissions = PermissionUtil.checkIfPermissionsAreGranted(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE);
            if (nonGrantedPermissions != null) {
                requestPermissions(nonGrantedPermissions, REQUEST_CODE_WRITE_STORAGE_EXPORT);
            } else {
                handleExportAction();
            }
            return false;
        }
    });
    mRestore.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            // Check for external storage permissions
            String[] nonGrantedPermissions = PermissionUtil.checkIfPermissionsAreGranted(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE);
            if (nonGrantedPermissions != null) {
                requestPermissions(nonGrantedPermissions, REQUEST_CODE_WRITE_STORAGE_IMPORT);
            } else {
                handleImportAction();
            }
            return false;
        }
    });
    mAbout = findPreference(getResources().getString(R.string.settings_about_key));
    mAbout.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            Intent goToAboutActivity = new Intent(packageContext, AboutActivity.class);
            startActivity(goToAboutActivity);
            return true;
        }
    });
    mRate = findPreference(getResources().getString(R.string.remindy_settings_rate_key));
    mRate.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            Intent playStoreIntent = new Intent(Intent.ACTION_VIEW);
            playStoreIntent.setData(Uri.parse(getResources().getString(R.string.url_market)));
            startActivity(playStoreIntent);
            return true;
        }
    });
    mContact = findPreference(getResources().getString(R.string.remindy_settings_contact_key));
    mContact.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", getResources().getString(R.string.address_email), null));
            startActivity(Intent.createChooser(emailIntent, "Send email..."));
            return true;
        }
    });
}
Also used : Context(android.content.Context) AboutActivity(ve.com.abicelis.remindy.app.activities.AboutActivity) ListPreference(android.support.v7.preference.ListPreference) Preference(android.support.v7.preference.Preference) Intent(android.content.Intent) PlaceListActivity(ve.com.abicelis.remindy.app.activities.PlaceListActivity) SettingsActivity(ve.com.abicelis.remindy.app.activities.SettingsActivity)

Aggregations

PreferenceScreen (android.support.v7.preference.PreferenceScreen)24 ListPreference (android.support.v7.preference.ListPreference)19 ContentResolver (android.content.ContentResolver)15 Preference (android.support.v7.preference.Preference)11 SwitchPreference (android.support.v14.preference.SwitchPreference)9 Resources (android.content.res.Resources)8 Context (android.content.Context)5 Intent (android.content.Intent)5 Activity (android.app.Activity)3 OnPreferenceChangeListener (android.support.v7.preference.Preference.OnPreferenceChangeListener)3 RestrictionEntry (android.content.RestrictionEntry)2 MultiSelectListPreference (android.support.v14.preference.MultiSelectListPreference)2 CheckBoxPreference (android.support.v7.preference.CheckBoxPreference)2 PreferenceCategory (android.support.v7.preference.PreferenceCategory)2 View (android.view.View)2 HashSet (java.util.HashSet)2 UiModeManager (android.app.UiModeManager)1 BluetoothAdapter (android.bluetooth.BluetoothAdapter)1 BluetoothPan (android.bluetooth.BluetoothPan)1 IntentFilter (android.content.IntentFilter)1