-
-
Save RamitPahwa/8592a307e6a69f028e3556ecf71afc8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static final String AFW_RESTRICION_PREFERENCES = "com.adobe.reader.restrictions"; | |
public static final String ENABLE_HELLO_PREFS_KEY = "enablePrintingKey"; | |
private static final String KEY_CAN_SAY_HELLO = "can_say_hello"; | |
private boolean getPreferenceValue(Context context, Bundle restrictions, String keyValue, @BoolRes int id) | |
{ | |
boolean enableKey = context.getResources().getBoolean(id); | |
if (restrictions != null && restrictions.containsKey(keyValue)) | |
{ | |
enableKey = restrictions.getBoolean(keyValue); | |
} | |
return enableKey; | |
} | |
private boolean isEnabledInAFW(Context context, String preferenceKey, @BoolRes int id) | |
{ | |
boolean isEnabled = false; | |
if(context != null) | |
{ | |
SharedPreferences preferences = context.getSharedPreferences(AFW_RESTRICION_PREFERENCES, Context.MODE_PRIVATE); | |
isEnabled = preferences.getBoolean(preferenceKey, context.getResources().getBoolean(id)); | |
} | |
return isEnabled; | |
} | |
private void resolveRestrictions() | |
{ | |
RestrictionsManager manager = (RestrictionsManager) getActivity().getSystemService(Context.RESTRICTIONS_SERVICE); | |
Bundle restrictions = manager.getApplicationRestrictions(); | |
List<RestrictionEntry> entries = manager.getManifestRestrictions(getActivity().getApplicationContext().getPackageName()); | |
SharedPreferences preferences = getContext().getSharedPreferences(AFW_RESTRICION_PREFERENCES, Context.MODE_PRIVATE); | |
for (RestrictionEntry entry : entries) | |
{ | |
String key = entry.getKey(); | |
String preferencesKey = null; | |
boolean preferencesValue = false; | |
Log.d(TAG, "key: " + key); | |
if (key.equals(KEY_CAN_SAY_HELLO)) | |
{ | |
preferencesKey = ENABLE_HELLO_PREFS_KEY; | |
preferencesValue = getPreferenceValue(getContext(), restrictions, KEY_CAN_SAY_HELLO, R.bool.default_can_say_hello); | |
} | |
if (preferencesKey != null) | |
{ | |
SharedPreferences.Editor editor = preferences.edit(); | |
editor.putBoolean(preferencesKey, preferencesValue); | |
editor.apply(); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment