Java Code Examples for androidx.preference.PreferenceManager#getSharedPreferences()

The following examples show how to use androidx.preference.PreferenceManager#getSharedPreferences() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EventPreferencesNFC.java    From PhoneProfilesPlus with Apache License 2.0 6 votes vote down vote up
@Override
void checkPreferences(PreferenceManager prefMng, Context context)
{
    boolean enabled = Event.isEventPreferenceAllowed(PREF_EVENT_NFC_ENABLED, context).allowed == PreferenceAllowed.PREFERENCE_ALLOWED;
    Preference nfcTagsPreference = prefMng.findPreference(PREF_EVENT_NFC_NFC_TAGS);
    Preference permanentRunPreference = prefMng.findPreference(PREF_EVENT_NFC_PERMANENT_RUN);
    Preference durationPreference = prefMng.findPreference(PREF_EVENT_NFC_DURATION);
    if (nfcTagsPreference != null)
        nfcTagsPreference.setEnabled(enabled);
    if (permanentRunPreference != null)
        permanentRunPreference.setEnabled(enabled);

    SharedPreferences preferences = prefMng.getSharedPreferences();
    if (preferences != null) {
        boolean permanentRun = preferences.getBoolean(PREF_EVENT_NFC_PERMANENT_RUN, false);
        enabled = enabled && (!permanentRun);
        if (durationPreference != null)
            durationPreference.setEnabled(enabled);
    }
}
 
Example 2
Source File: PhoneProfilesPrefsActivity.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreatePreferences(Bundle bundle, String rootKey) {
    //PPApplication.logE("PhoneProfilesPrefsFragment.onCreatePreferences", "from PhoneProfilesPrefsNotifications");

    PreferenceManager prefMng = getPreferenceManager();
    SharedPreferences preferences = prefMng.getSharedPreferences();
    if (getContext() != null) {
        SharedPreferences applicationPreferences = getContext().getApplicationContext().getSharedPreferences(PPApplication.APPLICATION_PREFS_NAME, Activity.MODE_PRIVATE);
        loadSharedPreferences(preferences, applicationPreferences);
    }

    setPreferencesFromResource(R.xml.phone_profiles_prefs_notifications, rootKey);
}
 
Example 3
Source File: PhoneProfilesPrefsActivity.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreatePreferences(Bundle bundle, String rootKey) {
    //PPApplication.logE("PhoneProfilesPrefsFragment.onCreatePreferences", "from PhoneProfilesPrefsActivator");

    PreferenceManager prefMng = getPreferenceManager();
    SharedPreferences preferences = prefMng.getSharedPreferences();
    if (getContext() != null) {
        SharedPreferences applicationPreferences = getContext().getApplicationContext().getSharedPreferences(PPApplication.APPLICATION_PREFS_NAME, Activity.MODE_PRIVATE);
        loadSharedPreferences(preferences, applicationPreferences);
    }

    setPreferencesFromResource(R.xml.phone_profiles_prefs_activator, rootKey);
}
 
Example 4
Source File: PhoneProfilesPrefsActivity.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreatePreferences(Bundle bundle, String rootKey) {
    //PPApplication.logE("PhoneProfilesPrefsFragment.onCreatePreferences", "from PhoneProfilesPrefsOrientationScanning");

    PreferenceManager prefMng = getPreferenceManager();
    SharedPreferences preferences = prefMng.getSharedPreferences();
    if (getContext() != null) {
        SharedPreferences applicationPreferences = getContext().getApplicationContext().getSharedPreferences(PPApplication.APPLICATION_PREFS_NAME, Activity.MODE_PRIVATE);
        loadSharedPreferences(preferences, applicationPreferences);
    }

    setPreferencesFromResource(R.xml.phone_profiles_prefs_orientation_scanning, rootKey);
}
 
Example 5
Source File: PhoneProfilesPrefsActivity.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreatePreferences(Bundle bundle, String rootKey) {
    //PPApplication.logE("PhoneProfilesPrefsFragment.onCreatePreferences", "from PhoneProfilesPrefsMobileCellsScanning");

    PreferenceManager prefMng = getPreferenceManager();
    SharedPreferences preferences = prefMng.getSharedPreferences();
    if (getContext() != null) {
        SharedPreferences applicationPreferences = getContext().getApplicationContext().getSharedPreferences(PPApplication.APPLICATION_PREFS_NAME, Activity.MODE_PRIVATE);
        loadSharedPreferences(preferences, applicationPreferences);
    }

    setPreferencesFromResource(R.xml.phone_profiles_prefs_mobile_cells_scanning, rootKey);
}
 
Example 6
Source File: EventPreferencesTime.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
@Override
void checkPreferences(PreferenceManager prefMng, Context context) {
    SharedPreferences preferences = prefMng.getSharedPreferences();
    setSummary(prefMng, PREF_EVENT_TIME_LOCATION_SYSTEM_SETTINGS, preferences, context);
    setSummary(prefMng, PREF_EVENT_TIME_APP_SETTINGS, preferences, context);
    setCategorySummary(prefMng, preferences, context);
}
 
Example 7
Source File: PhoneProfilesPrefsActivity.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreatePreferences(Bundle bundle, String rootKey) {
    //PPApplication.logE("PhoneProfilesPrefsFragment.onCreatePreferences", "from PhoneProfilesPrefsWifiScanning");

    PreferenceManager prefMng = getPreferenceManager();
    SharedPreferences preferences = prefMng.getSharedPreferences();
    if (getContext() != null) {
        SharedPreferences applicationPreferences = getContext().getApplicationContext().getSharedPreferences(PPApplication.APPLICATION_PREFS_NAME, Activity.MODE_PRIVATE);
        loadSharedPreferences(preferences, applicationPreferences);
    }

    setPreferencesFromResource(R.xml.phone_profiles_prefs_wifi_scanning, rootKey);
}
 
Example 8
Source File: PhoneProfilesPrefsActivity.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreatePreferences(Bundle bundle, String rootKey) {
    //PPApplication.logE("PhoneProfilesPrefsFragment.onCreatePreferences", "from PhoneProfilesPrefsLocationScanning");

    PreferenceManager prefMng = getPreferenceManager();
    SharedPreferences preferences = prefMng.getSharedPreferences();
    if (getContext() != null) {
        SharedPreferences applicationPreferences = getContext().getApplicationContext().getSharedPreferences(PPApplication.APPLICATION_PREFS_NAME, Activity.MODE_PRIVATE);
        loadSharedPreferences(preferences, applicationPreferences);
    }

    setPreferencesFromResource(R.xml.phone_profiles_prefs_location_scanning, rootKey);
}
 
Example 9
Source File: PhoneProfilesPrefsActivity.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreatePreferences(Bundle bundle, String rootKey) {
    //PPApplication.logE("PhoneProfilesPrefsFragment.onCreatePreferences", "from PhoneProfilesPrefsBackgroundScanning");

    PreferenceManager prefMng = getPreferenceManager();
    SharedPreferences preferences = prefMng.getSharedPreferences();
    if (getContext() != null) {
        SharedPreferences applicationPreferences = getContext().getApplicationContext().getSharedPreferences(PPApplication.APPLICATION_PREFS_NAME, Activity.MODE_PRIVATE);
        loadSharedPreferences(preferences, applicationPreferences);
    }

    setPreferencesFromResource(R.xml.phone_profiles_prefs_background_scanning, rootKey);
}
 
Example 10
Source File: PhoneProfilesPrefsActivity.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreatePreferences(Bundle bundle, String rootKey) {
    //PPApplication.logE("PhoneProfilesPrefsFragment.onCreatePreferences", "from PhoneProfilesPrefsEventRun");

    PreferenceManager prefMng = getPreferenceManager();
    SharedPreferences preferences = prefMng.getSharedPreferences();
    if (getContext() != null) {
        SharedPreferences applicationPreferences = getContext().getApplicationContext().getSharedPreferences(PPApplication.APPLICATION_PREFS_NAME, Activity.MODE_PRIVATE);
        loadSharedPreferences(preferences, applicationPreferences);
    }

    setPreferencesFromResource(R.xml.phone_profiles_prefs_event_run, rootKey);
}
 
Example 11
Source File: PhoneProfilesPrefsActivity.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreatePreferences(Bundle bundle, String rootKey) {
    //PPApplication.logE("PhoneProfilesPrefsFragment.onCreatePreferences", "from PhoneProfilesPrefsProfileActivation");

    PreferenceManager prefMng = getPreferenceManager();
    SharedPreferences preferences = prefMng.getSharedPreferences();
    if (getContext() != null) {
        SharedPreferences applicationPreferences = getContext().getApplicationContext().getSharedPreferences(PPApplication.APPLICATION_PREFS_NAME, Activity.MODE_PRIVATE);
        loadSharedPreferences(preferences, applicationPreferences);
    }

    setPreferencesFromResource(R.xml.phone_profiles_prefs_profile_activation, rootKey);
}
 
Example 12
Source File: PrefixedSharedPreferences.java    From EdXposedManager with GNU General Public License v3.0 5 votes vote down vote up
public static void injectToPreferenceManager(PreferenceManager manager, String prefix) {
    SharedPreferences prefixedPrefs = new PrefixedSharedPreferences(manager.getSharedPreferences(), prefix);

    try {
        Field fieldSharedPref = PreferenceManager.class.getDeclaredField("mSharedPreferences");
        fieldSharedPref.setAccessible(true);
        fieldSharedPref.set(manager, prefixedPrefs);
    } catch (Throwable t) {
        throw new RuntimeException(t);
    }
}
 
Example 13
Source File: PhoneProfilesPrefsActivity.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreatePreferences(Bundle bundle, String rootKey) {
    //PPApplication.logE("PhoneProfilesPrefsFragment.onCreatePreferences", "from PhoneProfilesPrefsWidgetList");

    PreferenceManager prefMng = getPreferenceManager();
    SharedPreferences preferences = prefMng.getSharedPreferences();
    if (getContext() != null) {
        SharedPreferences applicationPreferences = getContext().getApplicationContext().getSharedPreferences(PPApplication.APPLICATION_PREFS_NAME, Activity.MODE_PRIVATE);
        loadSharedPreferences(preferences, applicationPreferences);
    }

    setPreferencesFromResource(R.xml.phone_profiles_prefs_widget_list, rootKey);
}
 
Example 14
Source File: PhoneProfilesPrefsActivity.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreatePreferences(Bundle bundle, String rootKey) {
    //PPApplication.logE("PhoneProfilesPrefsFragment.onCreatePreferences", "from PhoneProfilesPrefsSystem");

    PreferenceManager prefMng = getPreferenceManager();
    SharedPreferences preferences = prefMng.getSharedPreferences();
    if (getContext() != null) {
        SharedPreferences applicationPreferences = getContext().getApplicationContext().getSharedPreferences(PPApplication.APPLICATION_PREFS_NAME, Activity.MODE_PRIVATE);
        loadSharedPreferences(preferences, applicationPreferences);
    }

    setPreferencesFromResource(R.xml.phone_profiles_prefs_system, rootKey);
}
 
Example 15
Source File: PhoneProfilesPrefsActivity.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreatePreferences(Bundle bundle, String rootKey) {
    //PPApplication.logE("PhoneProfilesPrefsFragment.onCreatePreferences", "from PhoneProfilesPrefsSamsungEdgePanel");

    PreferenceManager prefMng = getPreferenceManager();
    SharedPreferences preferences = prefMng.getSharedPreferences();
    if (getContext() != null) {
        SharedPreferences applicationPreferences = getContext().getApplicationContext().getSharedPreferences(PPApplication.APPLICATION_PREFS_NAME, Activity.MODE_PRIVATE);
        loadSharedPreferences(preferences, applicationPreferences);
    }

    setPreferencesFromResource(R.xml.phone_profiles_prefs_samsung_edge_panel, rootKey);
}
 
Example 16
Source File: PhoneProfilesPrefsActivity.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreatePreferences(Bundle bundle, String rootKey) {
    //PPApplication.logE("PhoneProfilesPrefsFragment.onCreatePreferences", "from PhoneProfilesPrefsInterface");

    PreferenceManager prefMng = getPreferenceManager();
    SharedPreferences preferences = prefMng.getSharedPreferences();
    if (getContext() != null) {
        SharedPreferences applicationPreferences = getContext().getApplicationContext().getSharedPreferences(PPApplication.APPLICATION_PREFS_NAME, Activity.MODE_PRIVATE);
        loadSharedPreferences(preferences, applicationPreferences);
    }

    setPreferencesFromResource(R.xml.phone_profiles_prefs_interface, rootKey);
}
 
Example 17
Source File: PhoneProfilesPrefsActivity.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreatePreferences(Bundle bundle, String rootKey) {
    //PPApplication.logE("PhoneProfilesPrefsFragment.onCreatePreferences", "from PhoneProfilesPrefsRoot");

    PreferenceManager prefMng = getPreferenceManager();
    SharedPreferences preferences = prefMng.getSharedPreferences();
    if (getContext() != null) {
        SharedPreferences applicationPreferences = getContext().getApplicationContext().getSharedPreferences(PPApplication.APPLICATION_PREFS_NAME, Activity.MODE_PRIVATE);
        loadSharedPreferences(preferences, applicationPreferences);
    }

    setPreferencesFromResource(R.xml.phone_profiles_prefs_root, rootKey);
}
 
Example 18
Source File: PhoneProfilesPrefsActivity.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreatePreferences(Bundle bundle, String rootKey) {
    //PPApplication.logE("PhoneProfilesPrefsFragment.onCreatePreferences", "from PhoneProfilesPrefsWidgetIcon");

    PreferenceManager prefMng = getPreferenceManager();
    SharedPreferences preferences = prefMng.getSharedPreferences();
    if (getContext() != null) {
        SharedPreferences applicationPreferences = getContext().getApplicationContext().getSharedPreferences(PPApplication.APPLICATION_PREFS_NAME, Activity.MODE_PRIVATE);
        loadSharedPreferences(preferences, applicationPreferences);
    }

    setPreferencesFromResource(R.xml.phone_profiles_prefs_widget_icon, rootKey);
}
 
Example 19
Source File: PhoneProfilesPrefsActivity.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreatePreferences(Bundle bundle, String rootKey) {
    //PPApplication.logE("PhoneProfilesPrefsFragment.onCreatePreferences", "from PhoneProfilesPrefsEditor");

    PreferenceManager prefMng = getPreferenceManager();
    SharedPreferences preferences = prefMng.getSharedPreferences();
    if (getContext() != null) {
        SharedPreferences applicationPreferences = getContext().getApplicationContext().getSharedPreferences(PPApplication.APPLICATION_PREFS_NAME, Activity.MODE_PRIVATE);
        loadSharedPreferences(preferences, applicationPreferences);
    }

    setPreferencesFromResource(R.xml.phone_profiles_prefs_editor, rootKey);
}
 
Example 20
Source File: EventPreferencesOrientation.java    From PhoneProfilesPlus with Apache License 2.0 4 votes vote down vote up
@Override
void checkPreferences(PreferenceManager prefMng, Context context) {
    SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    boolean hasAccelerometer = (sensorManager != null) && (sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) != null);
    boolean hasMagneticField = (sensorManager != null) && (sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) != null);
    boolean hasProximity = (sensorManager != null) && (sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY) != null);
    boolean hasLight = (sensorManager != null) && (sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT) != null);
    boolean enabledAll = (hasAccelerometer) && (hasMagneticField);
    Preference preference = prefMng.findPreference(PREF_EVENT_ORIENTATION_DISPLAY);
    if (preference != null) {
        if (!hasAccelerometer)
            preference.setSummary(context.getString(R.string.profile_preferences_device_not_allowed)+
                    ": "+context.getString(R.string.preference_not_allowed_reason_no_hardware));
        preference.setEnabled(hasAccelerometer);
    }
    preference = prefMng.findPreference(PREF_EVENT_ORIENTATION_SIDES);
    if (preference != null) {
        if (!enabledAll)
            preference.setSummary(context.getString(R.string.profile_preferences_device_not_allowed)+
                    ": "+context.getString(R.string.preference_not_allowed_reason_no_hardware));
        preference.setEnabled(enabledAll);
    }
    boolean enabled = hasProximity;
    preference = prefMng.findPreference(PREF_EVENT_ORIENTATION_DISTANCE);
    if (preference != null) {
        if (!enabled)
            preference.setSummary(context.getString(R.string.profile_preferences_device_not_allowed)+
                    ": "+context.getString(R.string.preference_not_allowed_reason_no_hardware));
        preference.setEnabled(enabled);
    }
    SwitchPreferenceCompat switchPreference = prefMng.findPreference(PREF_EVENT_ORIENTATION_CHECK_LIGHT);
    if (switchPreference != null) {
        boolean checkLight = switchPreference.isChecked();
        if (checkLight) {
            enabled = hasLight;
            preference = prefMng.findPreference(PREF_EVENT_ORIENTATION_LIGHT_MIN);
            if (preference != null) {
                if (!enabled)
                    preference.setSummary(context.getString(R.string.profile_preferences_device_not_allowed) +
                            ": " + context.getString(R.string.preference_not_allowed_reason_no_hardware));
                preference.setEnabled(enabled);
            }
            preference = prefMng.findPreference(PREF_EVENT_ORIENTATION_LIGHT_MAX);
            if (preference != null) {
                if (!enabled)
                    preference.setSummary(context.getString(R.string.profile_preferences_device_not_allowed) +
                            ": " + context.getString(R.string.preference_not_allowed_reason_no_hardware));
                preference.setEnabled(enabled);
            }
        }
    }
    enabled = PPPExtenderBroadcastReceiver.isEnabled(context.getApplicationContext(), PPApplication.VERSION_CODE_EXTENDER_3_0);
    ApplicationsMultiSelectDialogPreferenceX applicationsPreference = prefMng.findPreference(PREF_EVENT_ORIENTATION_IGNORED_APPLICATIONS);
    if (applicationsPreference != null) {
        applicationsPreference.setEnabled(enabled);
        applicationsPreference.setSummaryAMSDP();
    }
    SharedPreferences preferences = prefMng.getSharedPreferences();
    setSummary(prefMng, PREF_EVENT_ORIENTATION_APP_SETTINGS, preferences, context);
    setCategorySummary(prefMng, preferences, context);
}