Make the shared preferences plugin more flexible
Summary: You don't necessarily need / have your shared preferences defined in a file that is your package name. This adds the ability to pass in the name + mode you need to read the correct shared preferences file. Reviewed By: sjkirby Differential Revision: D8661573 fbshipit-source-id: 49e57b0371228eca7fc4f06e8ba65ff8cc059b11
This commit is contained in:
committed by
Facebook Github Bot
parent
55930db6a6
commit
ceb16db812
@@ -24,8 +24,36 @@ public class SharedPreferencesSonarPlugin implements SonarPlugin {
|
||||
private SonarConnection mConnection;
|
||||
private final SharedPreferences mSharedPreferences;
|
||||
|
||||
/**
|
||||
* Creates a {@link android.content.SharedPreferences} plugin for Sonar
|
||||
*
|
||||
* @param context The context to retrieve the file from. Will use the package name as the file
|
||||
* name with {@link Context#MODE_PRIVATE}.
|
||||
*/
|
||||
public SharedPreferencesSonarPlugin(Context context) {
|
||||
mSharedPreferences = context.getSharedPreferences(context.getPackageName(), MODE_PRIVATE);
|
||||
this(context, context.getPackageName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link android.content.SharedPreferences} plugin for Sonar
|
||||
*
|
||||
* @param context The context to retrieve the file from. Will use the name as the file name with
|
||||
* {@link Context#MODE_PRIVATE}.
|
||||
* @param name The preference file name.
|
||||
*/
|
||||
public SharedPreferencesSonarPlugin(Context context, String name) {
|
||||
this(context, name, MODE_PRIVATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link android.content.SharedPreferences} plugin for Sonar
|
||||
*
|
||||
* @param context The context to retrieve the file from.
|
||||
* @param name The preference file name.
|
||||
* @param mode The Context mode to utilize.
|
||||
*/
|
||||
public SharedPreferencesSonarPlugin(Context context, String name, int mode) {
|
||||
mSharedPreferences = context.getSharedPreferences(name, mode);
|
||||
|
||||
mSharedPreferences.registerOnSharedPreferenceChangeListener(
|
||||
new SharedPreferences.OnSharedPreferenceChangeListener() {
|
||||
|
||||
Reference in New Issue
Block a user