use of com.cometchat.pro.core.Call in project android-java-chat-push-notification-app by cometchat-pro.
the class PushNotificationActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_push_notification);
if (!Utils.hasPermissions(this, permissions)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(permissions, UIKitConstants.RequestCode.RECORD);
}
}
progressDialog = new ProgressDialog(this);
progressDialog.setTitle(getResources().getString(R.string.please_wait));
progressDialog.setMessage(getResources().getString(R.string.media_uploading));
progressDialog.setCancelable(false);
moreBtn = findViewById(R.id.more_btn);
titleTv = findViewById(R.id.title_tv);
messageTv = findViewById(R.id.message_tv);
uid = findViewById(R.id.uid);
uidLayout = findViewById(R.id.uid_layout);
recieverType = findViewById(R.id.reciever_type);
user = findViewById(R.id.users);
group = findViewById(R.id.groups);
message = findViewById(R.id.message);
textMessage = findViewById(R.id.text_message);
mediaMessage = findViewById(R.id.media_message);
audioCall = findViewById(R.id.audio_call);
videoCall = findViewById(R.id.video_call);
customMessage = findViewById(R.id.custom_message);
recieverType.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup g, int checkedId) {
if (user.isChecked()) {
uidLayout.setHint(getResources().getString(R.string.enter_uid));
receiver = CometChatConstants.RECEIVER_TYPE_USER;
}
if (group.isChecked()) {
uidLayout.setHint(getResources().getString(R.string.enter_guid));
receiver = CometChatConstants.RECEIVER_TYPE_GROUP;
}
}
});
moreBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MoreActionFragment moreActionFragment = new MoreActionFragment();
moreActionFragment.show(getSupportFragmentManager(), moreActionFragment.getTag());
}
});
textMessage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (uid.getText().toString().trim().isEmpty()) {
uid.setError(getResources().getString(R.string.fill_this_field));
} else if (message.getText().toString().isEmpty()) {
message.setError(getResources().getString(R.string.fill_this_field));
} else {
// subscribePushNotification();
TextMessage textMessage = new TextMessage(uid.getText().toString(), message.getText().toString(), receiver);
sendMessage(textMessage);
message.setText("");
}
}
});
mediaMessage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (uid.getText().toString().isEmpty())
uid.setError(getResources().getString(R.string.fill_this_field));
else {
if (Utils.hasPermissions(PushNotificationActivity.this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE })) {
startActivityForResult(MediaUtils.openGallery(PushNotificationActivity.this), UIKitConstants.RequestCode.GALLERY);
} else {
requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE }, UIKitConstants.RequestCode.GALLERY);
}
}
}
});
customMessage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (uid.getText().toString().isEmpty())
uid.setError(getResources().getString(R.string.fill_this_field));
else {
try {
// subscribePushNotification();
JSONObject customData = new JSONObject();
customData.put("latitude", "19.0760");
customData.put("longitude", "72.8777");
CustomMessage customMessage = new CustomMessage(uid.getText().toString(), receiver, "location", customData);
JSONObject metaData = new JSONObject();
metaData.put("pushNotification", "You Received Custom Message");
customMessage.setMetadata(metaData);
sendMessage(customMessage);
} catch (Exception e) {
Log.e(TAG, "onClick: " + e.getMessage());
}
}
}
});
audioCall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (uid.getText().toString().isEmpty()) {
uid.setError(getResources().getString(R.string.fill_this_field));
} else {
Call call = new Call(uid.getText().toString(), receiver, CometChatConstants.CALL_TYPE_AUDIO);
initiateCall(call);
}
}
});
videoCall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (uid.getText().toString().isEmpty()) {
uid.setError(getResources().getString(R.string.fill_this_field));
} else {
Call call = new Call(uid.getText().toString(), receiver, CometChatConstants.CALL_TYPE_VIDEO);
initiateCall(call);
}
}
});
checkDarkMode();
}
use of com.cometchat.pro.core.Call in project android-java-chat-push-notification-app by cometchat-pro.
the class MissedCall method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_cometchat_missed_call, container, false);
rvCallList = view.findViewById(R.id.callList_rv);
CometChatError.init(getContext());
linearLayoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
rvCallList.setLayoutManager(linearLayoutManager);
noCallView = view.findViewById(R.id.no_call_vw);
rvCallList.setItemClickListener(new OnItemClickListener<Call>() {
@Override
public void OnItemClick(Call var, int position) {
if (var.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_USER)) {
User user;
if (((User) var.getCallInitiator()).getUid().equals(CometChat.getLoggedInUser().getUid())) {
user = ((User) var.getCallReceiver());
} else {
user = (User) var.getCallInitiator();
}
Intent intent = new Intent(getContext(), CometChatUserDetailScreenActivity.class);
intent.putExtra(UIKitConstants.IntentStrings.UID, user.getUid());
intent.putExtra(UIKitConstants.IntentStrings.NAME, user.getName());
intent.putExtra(UIKitConstants.IntentStrings.AVATAR, user.getAvatar());
intent.putExtra(UIKitConstants.IntentStrings.LINK, user.getLink());
intent.putExtra(UIKitConstants.IntentStrings.STATUS, user.getStatus());
intent.putExtra(UIKitConstants.IntentStrings.IS_BLOCKED_BY_ME, user.isBlockedByMe());
intent.putExtra(UIKitConstants.IntentStrings.FROM_CALL_LIST, true);
startActivity(intent);
} else {
Group group;
group = ((Group) var.getCallReceiver());
Intent intent = new Intent(getContext(), CometChatGroupDetailActivity.class);
intent.putExtra(UIKitConstants.IntentStrings.GUID, group.getGuid());
intent.putExtra(UIKitConstants.IntentStrings.NAME, group.getName());
intent.putExtra(UIKitConstants.IntentStrings.AVATAR, group.getIcon());
intent.putExtra(UIKitConstants.IntentStrings.MEMBER_SCOPE, group.getScope());
intent.putExtra(UIKitConstants.IntentStrings.GROUP_OWNER, group.getOwner());
intent.putExtra(UIKitConstants.IntentStrings.GROUP_TYPE, group.getGroupType());
intent.putExtra(UIKitConstants.IntentStrings.MEMBER_COUNT, group.getMembersCount());
intent.putExtra(UIKitConstants.IntentStrings.GROUP_PASSWORD, group.getPassword());
intent.putExtra(UIKitConstants.IntentStrings.GROUP_DESC, group.getDescription());
startActivity(intent);
}
}
});
rvCallList.setItemCallClickListener(new OnItemClickListener<Call>() {
@Override
public void OnItemClick(Call var, int position) {
checkOnGoingCall(var);
}
});
rvCallList.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
if (!rvCallList.canScrollVertically(1)) {
getCallList();
}
}
});
return view;
}
use of com.cometchat.pro.core.Call in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatStartCallActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
activity = this;
setContentView(R.layout.activity_cometchat_start_call);
ongoingCallService = new OngoingCallService();
mServiceIntent = new Intent(this, ongoingCallService.getClass());
isDefaultCall = getIntent().getBooleanExtra(UIKitConstants.IntentStrings.IS_DEFAULT_CALL, false);
if (isDefaultCall && !isMyServiceRunning(ongoingCallService.getClass())) {
startService(mServiceIntent);
}
mainView = findViewById(R.id.call_view);
connectingLayout = findViewById(R.id.connecting_to_call);
sessionID = getIntent().getStringExtra(UIKitConstants.IntentStrings.SESSION_ID);
type = getIntent().getStringExtra(UIKitConstants.IntentStrings.TYPE);
if (type != null && type.equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_USER))
callSettings = new CallSettings.CallSettingsBuilder(this, mainView).setSessionId(sessionID).setMode(CallSettings.MODE_SINGLE).build();
else
callSettings = new CallSettings.CallSettingsBuilder(this, mainView).setSessionId(sessionID).build();
CometChatError.init(this);
Log.e("startCallActivity: ", sessionID + " " + type);
CometChat.startCall(callSettings, new CometChat.OngoingCallListener() {
@Override
public void onUserListUpdated(List<User> list) {
Log.e("onUserListUpdated: ", list.toString());
}
@Override
public void onAudioModesUpdated(List<AudioMode> list) {
Log.e("onAudioModesUpdated: ", list.toString());
}
@Override
public void onUserJoined(User user) {
connectingLayout.setVisibility(View.GONE);
CometChatSnackBar.show(CometChatStartCallActivity.this, mainView, getString(R.string.user_joined) + ":" + user.getName(), CometChatSnackBar.INFO);
Log.e("onUserJoined: ", user.getUid());
}
@Override
public void onUserLeft(User user) {
if (user != null) {
CometChatSnackBar.show(CometChatStartCallActivity.this, mainView, getString(R.string.user_left) + ":" + user.getName(), CometChatSnackBar.INFO);
Log.e("onUserLeft: ", user.getUid());
if (callSettings.getMode().equals(CallSettings.MODE_SINGLE)) {
endCall();
}
} else {
Log.e("onUserLeft: ", "triggered");
}
}
@Override
public void onError(CometChatException e) {
stopService(mServiceIntent);
Log.e("onstartcallError: ", e.getMessage());
CometChatSnackBar.show(CometChatStartCallActivity.this, mainView, CometChatError.localized(e), CometChatSnackBar.ERROR);
}
@Override
public void onCallEnded(Call call) {
stopService(mServiceIntent);
Log.e("TAG", "onCallEnded: ");
finish();
}
});
}
use of com.cometchat.pro.core.Call in project android-java-chat-push-notification-app by cometchat-pro.
the class CallHistoryAdapter method onBindViewHolder.
/**
* This method is used to bind the ConversationViewHolder contents with conversation at given
* position. It set avatar, name, lastMessage, unreadMessageCount and messageTime of conversation
* in a respective ConversationViewHolder content. It checks whether conversation type is user
* or group and set name and avatar as accordingly. It also checks whether last message is text, media
* or file and modify txtUserMessage view accordingly.
*
* @param callViewHolder is a object of ConversationViewHolder.
* @param position is a position of item in recyclerView.
*
* @see Conversation
*/
@Override
public void onBindViewHolder(@NonNull CallViewHolder callViewHolder, int position) {
BaseMessage baseMessage = callList.get(position);
Call call = (Call) baseMessage;
boolean isIncoming = false, isVideo = false, isMissed = false;
String callMessageText = "";
if (call.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_USER)) {
if (call.getSender().getUid().equals(loggedInUser)) {
if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_UNANSWERED)) {
if (call.getType().equals(CometChatConstants.CALL_TYPE_VIDEO)) {
callMessageText = context.getResources().getString(R.string.missed_video_call);
isVideo = true;
} else {
callMessageText = context.getResources().getString(R.string.missed_voice_call);
isVideo = false;
}
isMissed = true;
} else if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_REJECTED)) {
if (call.getType().equals(CometChatConstants.CALL_TYPE_VIDEO)) {
callMessageText = context.getResources().getString(R.string.rejected_video_call);
isVideo = true;
} else {
callMessageText = context.getResources().getString(R.string.rejected_voice_call);
isVideo = false;
}
} else {
if (call.getType().equals(CometChatConstants.CALL_TYPE_VIDEO)) {
callMessageText = context.getResources().getString(R.string.outgoing_video_call);
isVideo = true;
} else {
callMessageText = context.getResources().getString(R.string.outgoing_voice_call);
isVideo = false;
}
}
isIncoming = false;
} else {
if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_UNANSWERED)) {
if (call.getType().equals(CometChatConstants.CALL_TYPE_VIDEO)) {
callMessageText = context.getResources().getString(R.string.missed_video_call);
isVideo = true;
} else {
callMessageText = context.getResources().getString(R.string.missed_voice_call);
isVideo = false;
}
isMissed = true;
} else if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_REJECTED)) {
if (call.getType().equals(CometChatConstants.CALL_TYPE_VIDEO)) {
callMessageText = context.getResources().getString(R.string.rejected_video_call);
isVideo = true;
} else {
callMessageText = context.getResources().getString(R.string.rejected_voice_call);
isVideo = false;
}
} else {
if (call.getType().equals(CometChatConstants.CALL_TYPE_VIDEO)) {
callMessageText = context.getResources().getString(R.string.incoming_video_call);
isVideo = true;
} else {
callMessageText = context.getResources().getString(R.string.incoming_audio_call);
isVideo = false;
}
}
isIncoming = true;
}
}
// }
if (isVideo) {
if (isIncoming) {
callViewHolder.callHistoryRowBinding.callInfoTv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_incoming_video_call, 0, 0, 0);
} else {
callViewHolder.callHistoryRowBinding.callInfoTv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_outgoing_video_call, 0, 0, 0);
}
} else {
if (isIncoming && isMissed) {
callViewHolder.callHistoryRowBinding.callInfoTv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_call_missed_incoming_24dp, 0, 0, 0);
} else if (isIncoming && !isMissed) {
callViewHolder.callHistoryRowBinding.callInfoTv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_incoming_call, 0, 0, 0);
} else if (!isIncoming && isMissed) {
callViewHolder.callHistoryRowBinding.callInfoTv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_call_missed_outgoing_24dp, 0, 0, 0);
} else {
callViewHolder.callHistoryRowBinding.callInfoTv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_outgoing_call, 0, 0, 0);
}
}
callViewHolder.callHistoryRowBinding.callTimeTv.setText(Utils.getHeaderDate(call.getInitiatedAt() * 1000));
callViewHolder.callHistoryRowBinding.callInfoTv.setText(callMessageText);
callViewHolder.callHistoryRowBinding.callDateTv.setText(Utils.getCallDate(call.getSentAt() * 1000));
callViewHolder.callHistoryRowBinding.getRoot().setTag(R.string.call, call);
}
use of com.cometchat.pro.core.Call in project android-java-chat-push-notification-app by cometchat-pro.
the class CallNotificationAction method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
String sessionID = intent.getStringExtra(UIKitConstants.IntentStrings.SESSION_ID);
Log.e(TAG, "onReceive: " + intent.getStringExtra(UIKitConstants.IntentStrings.SESSION_ID));
if (intent.getAction().equals("Answer_")) {
CometChat.acceptCall(sessionID, new CometChat.CallbackListener<Call>() {
@Override
public void onSuccess(Call call) {
Intent acceptIntent = new Intent(context, CometChatStartCallActivity.class);
acceptIntent.putExtra(UIKitConstants.IntentStrings.SESSION_ID, sessionID);
acceptIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
acceptIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(acceptIntent);
}
@Override
public void onError(CometChatException e) {
Toast.makeText(context, "Error " + e.getMessage(), Toast.LENGTH_LONG).show();
}
});
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.cancel(UIKitConstants.Notification.ID);
} else if (intent.getAction().equals("Decline_")) {
CometChat.rejectCall(sessionID, CometChatConstants.CALL_STATUS_REJECTED, new CometChat.CallbackListener<Call>() {
@Override
public void onSuccess(Call call) {
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.cancel(UIKitConstants.Notification.ID);
if (CometChatCallActivity.callActivity != null)
CometChatCallActivity.callActivity.finish();
}
@Override
public void onError(CometChatException e) {
Toast.makeText(context, "Error: " + e.getMessage(), Toast.LENGTH_LONG).show();
}
});
} else if (intent.getAction().equals("StartCall")) {
Log.e(TAG, "onReceive: StartCall");
Intent acceptIntent = new Intent(context, CometChatStartCallActivity.class);
acceptIntent.putExtra(UIKitConstants.IntentStrings.SESSION_ID, sessionID);
acceptIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
acceptIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(acceptIntent);
}
}
Aggregations