| 14792 |
manas |
1 |
package com.facebook.internal;
|
|
|
2 |
|
|
|
3 |
import android.content.Context;
|
|
|
4 |
import android.os.Bundle;
|
|
|
5 |
import com.facebook.widget.FacebookDialog;
|
|
|
6 |
|
|
|
7 |
import java.util.ArrayList;
|
|
|
8 |
import java.util.HashMap;
|
|
|
9 |
import java.util.Map;
|
|
|
10 |
import java.util.UUID;
|
|
|
11 |
|
|
|
12 |
/**
|
|
|
13 |
* com.facebook.internal is solely for the use of other packages within the Facebook SDK for Android. Use of
|
|
|
14 |
* any of the classes in this package is unsupported, and they may be modified or removed without warning at
|
|
|
15 |
* any time.
|
|
|
16 |
*/
|
|
|
17 |
public class PendingCallStore {
|
|
|
18 |
private static final String CALL_ID_ARRAY_KEY = "com.facebook.internal.PendingCallStore.callIdArrayKey";
|
|
|
19 |
private static final String CALL_KEY_PREFIX = "com.facebook.internal.PendingCallStore.";
|
|
|
20 |
|
|
|
21 |
private static PendingCallStore mInstance;
|
|
|
22 |
|
|
|
23 |
private Map<String, FacebookDialog.PendingCall> pendingCallMap = new HashMap<String, FacebookDialog.PendingCall>();
|
|
|
24 |
|
|
|
25 |
public static PendingCallStore getInstance() {
|
|
|
26 |
if (mInstance == null) {
|
|
|
27 |
createInstance();
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
return mInstance;
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
private synchronized static void createInstance() {
|
|
|
34 |
if (mInstance == null) {
|
|
|
35 |
mInstance = new PendingCallStore();
|
|
|
36 |
}
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
public void trackPendingCall(FacebookDialog.PendingCall pendingCall) {
|
|
|
40 |
if (pendingCall != null) {
|
|
|
41 |
pendingCallMap.put(pendingCall.getCallId().toString(), pendingCall);
|
|
|
42 |
}
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
public void stopTrackingPendingCall(UUID callId) {
|
|
|
46 |
if (callId != null) {
|
|
|
47 |
pendingCallMap.remove(callId.toString());
|
|
|
48 |
}
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
public FacebookDialog.PendingCall getPendingCallById(UUID callId) {
|
|
|
52 |
if (callId == null) {
|
|
|
53 |
return null;
|
|
|
54 |
}
|
|
|
55 |
return pendingCallMap.get(callId.toString());
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
public void saveInstanceState(Bundle outState) {
|
|
|
59 |
ArrayList<String> callIds = new ArrayList<String>(pendingCallMap.keySet());
|
|
|
60 |
outState.putStringArrayList(CALL_ID_ARRAY_KEY, callIds);
|
|
|
61 |
|
|
|
62 |
for(FacebookDialog.PendingCall pendingCall : pendingCallMap.values()) {
|
|
|
63 |
String stateKey = getSavedStateKeyForPendingCallId(pendingCall.getCallId().toString());
|
|
|
64 |
outState.putParcelable(stateKey, pendingCall);
|
|
|
65 |
}
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
public void restoreFromSavedInstanceState(Bundle savedInstanceState) {
|
|
|
69 |
ArrayList<String> callIds = savedInstanceState.getStringArrayList(CALL_ID_ARRAY_KEY);
|
|
|
70 |
if (callIds != null) {
|
|
|
71 |
for (String callId : callIds) {
|
|
|
72 |
String stateKey = getSavedStateKeyForPendingCallId(callId);
|
|
|
73 |
FacebookDialog.PendingCall pendingCall = savedInstanceState.getParcelable(stateKey);
|
|
|
74 |
|
|
|
75 |
if (pendingCall != null) {
|
|
|
76 |
pendingCallMap.put(pendingCall.getCallId().toString(), pendingCall);
|
|
|
77 |
}
|
|
|
78 |
}
|
|
|
79 |
}
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
private String getSavedStateKeyForPendingCallId(String pendingCallId) {
|
|
|
83 |
return CALL_KEY_PREFIX + pendingCallId;
|
|
|
84 |
}
|
|
|
85 |
}
|