本文整理汇总了Java中com.pubnub.api.Callback类的典型用法代码示例。如果您正苦于以下问题:Java Callback类的具体用法?Java Callback怎么用?Java Callback使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Callback类属于com.pubnub.api包,在下文中一共展示了Callback类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: listenToMessages
import com.pubnub.api.Callback; //导入依赖的package包/类
private void listenToMessages() {
try {
pb = new Pubnub(PUBNUB_PUB_KEY, PUBNUB_SUB_KEY);
pb.subscribe(tokenPrefix + uniqueId, new Callback() {
@Override
public void successCallback(String channel, Object message, String timetoken) {
if(message instanceof String) {
pendingAck.remove(channel);
return;
}
Message m = new Message((JSONObject)message);
pb.publish(tokenPrefix + m.getSenderId(), "ACK", new Callback() {});
Display.getInstance().callSerially(() -> {
addMessage(m);
respond(m);
});
}
});
} catch(PubnubException err) {
Log.e(err);
Dialog.show("Error", "There was a communication error: " + err, "OK", null);
}
}
示例2: getUserStatus
import com.pubnub.api.Callback; //导入依赖的package包/类
private void getUserStatus(final ChatUser user, final TextView statusView){
String stdByUser = user.getUserId() + Constants.STDBY_SUFFIX;
this.mPubNub.getState(stdByUser, user.getUserId(), new Callback() {
@Override
public void successCallback(String channel, Object message) {
JSONObject jsonMsg = (JSONObject) message;
try {
if (!jsonMsg.has(Constants.JSON_STATUS)) return;
final String status = jsonMsg.getString(Constants.JSON_STATUS);
user.setStatus(status);
((Activity)getContext()).runOnUiThread(new Runnable() {
@Override
public void run() {
statusView.setText(status);
}
});
} catch (JSONException e){
e.printStackTrace();
}
}
});
}
示例3: setUserStatus
import com.pubnub.api.Callback; //导入依赖的package包/类
private void setUserStatus(String status){
try {
JSONObject state = new JSONObject();
state.put(Constants.JSON_STATUS, status);
this.mPubNub.setState(this.stdByChannel, this.username, state, new Callback() {
@Override
public void successCallback(String channel, Object message) {
Log.d("MA-sUS","State Set: " + message.toString());
}
});
} catch (JSONException e){
e.printStackTrace();
}
}
示例4: getUserStatus
import com.pubnub.api.Callback; //导入依赖的package包/类
private void getUserStatus(String userId){
String stdByUser = userId + Constants.STDBY_SUFFIX;
this.mPubNub.getState(stdByUser, userId, new Callback() {
@Override
public void successCallback(String channel, Object message) {
Log.d("MA-gUS", "User Status: " + message.toString());
}
});
}
示例5: updateHistory
import com.pubnub.api.Callback; //导入依赖的package包/类
public void updateHistory(){
final List<HistoryItem> rtcHistory = new LinkedList<HistoryItem>();
String usrStdBy = this.mPubNub.getUUID() + Constants.STDBY_SUFFIX;
this.mPubNub.history(usrStdBy, 25, new Callback() {
@Override
public void successCallback(String channel, Object message) {
Log.d("HA-uH","HISTORY: " + message.toString());
try {
JSONArray historyArray = ((JSONArray) message).getJSONArray(0);
for(int i=0; i< historyArray.length(); i++){
JSONObject historyJson = historyArray.getJSONObject(i);
String userName = historyJson.getString(Constants.JSON_CALL_USER);
long timeStamp = historyJson.getLong(Constants.JSON_CALL_TIME);
ChatUser cUser = new ChatUser(userName);
if (users.containsKey(userName)){
cUser = users.get(userName);
} else {
users.put(userName, cUser);
}
rtcHistory.add(0, new HistoryItem(cUser, timeStamp));
}
values = rtcHistory;
updateAdapter();
} catch (JSONException e){
// e.printStackTrace();
}
}
});
}
示例6: rejectCall
import com.pubnub.api.Callback; //导入依赖的package包/类
/**
* Publish a hangup command if rejecting call.
* @param view
*/
public void rejectCall(View view){
JSONObject hangupMsg = PnPeerConnectionClient.generateHangupPacket(this.username);
this.mPubNub.publish(this.callUser,hangupMsg, new Callback() {
@Override
public void successCallback(String channel, Object message) {
Intent intent = new Intent(IncomingCallActivity.this, MainActivity.class);
startActivity(intent);
}
});
}
示例7: sendMessage
import com.pubnub.api.Callback; //导入依赖的package包/类
public static void sendMessage(String channelName,String message)
{
final Pubnub pubnub = new Pubnub("pub-c-f9d02ea4-19f1-4737-b3e1-ef2ce904b94f", "sub-c-3d547124-be29-11e5-8a35-0619f8945a4f");
final JSONObject data = new JSONObject();
try {
data.put("username",ParseUser.getCurrentUser().getUsername());
data.put("message",message);
data.put("displayname",ParseUser.getCurrentUser().getString("displayname"));
pubnub.publish(channelName, data, new Callback() {
});
} catch (JSONException e) {
e.printStackTrace();
}
}
示例8: publish
import com.pubnub.api.Callback; //导入依赖的package包/类
private static void publish(final String channel, final String payload) {
final Pubnub pubnub = sPubnub;
pubnub.publish(channel, payload, new Callback() {
@Override
public void successCallback(String arg0, Object arg1) {
}
});
}