-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathIntentBridgedPreferencesRequestedReceiver.java
More file actions
42 lines (35 loc) · 1.42 KB
/
IntentBridgedPreferencesRequestedReceiver.java
File metadata and controls
42 lines (35 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.crossbowffs.remotepreferences;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import java.util.Map;
/**
* <p>
* Receives requests to send the preferences and responds with
* the full set of preferences being sent as intent.
* </p>
*/
public abstract class IntentBridgedPreferencesRequestedReceiver extends BroadcastReceiver {
private final String mActionName;
private final SharedPreferences mSourcePreferences;
/**
* Initializes this receiver with the action name and
* the given {@link SharedPreferences} as source for preferences.
*
* @param actionName The actionName of the action.
* @param sourcePreferences The {@link SharedPreferences} used as source.
*/
public IntentBridgedPreferencesRequestedReceiver(String actionName, SharedPreferences sourcePreferences) {
mActionName = actionName;
mSourcePreferences = sourcePreferences;
}
@Override
public void onReceive(Context context, Intent receivedIntent) {
Intent preferencesIntent = new Intent(mActionName + ".PREFERENCES");
for (Map.Entry<String, ?> preference : mSourcePreferences.getAll().entrySet()) {
IntentBridgedUtils.setAsIntentExtra(preferencesIntent, preference.getKey(), preference.getValue());
}
context.sendBroadcast(preferencesIntent);
}
}