Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • In (Q-Municate) Android Application callActivity is Not Opening?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 600
    Answer it

    I am modifying (Q-Municate) application powered by (QuickBlox) but I am facing one problem. When, I receive calling notification; I launch calling activity but it's not getting appear instead application get's open normally but calling activity not appear , below is the code for CallActivity and QbCallChatHelper.

    QbCallChatHelper:>>>>>>

    public class QBCallChatHelper extends BaseHelper {

    private static final String TAG = QBCallChatHelper.class.getSimpleName();
    
    private static final int MAX_OPPONENTS_COUNT = 1;
    private static final int DISCONNECT_TIME = 30;
    private static final int ANSWER_TIME_INTERVAL = 60;
    
    private QBRTCClient qbRtcClient;
    private Class<? extends Activity> activityClass;
    
    private QBRTCSession currentQbRtcSession;
    private QBRTCClientSessionCallbacks qbRtcClientSessionCallbacks;
    
    private QBChatService chatService;
    
    private boolean isInitialized = false;
    
    public QBCallChatHelper(Context context) {
        super(context);
        chatService = QBChatService.getInstance();
    }
    
    public void init(QBChatService qbChatService) {
        if (!isInitialized) {
            superInit();
        }
    }
    
    private void superInit() {
        if (isLoggedInToChat()) {
            Log.i(TAG, "already logged in");
            initCallListener();
        } else {
            chatService.login(AppSession.getSession().getUser(), new QBEntityCallback() {
                @Override
                public void onSuccess(Object o, Bundle bundle) {
                    Log.i(TAG, "log in successful");
                    initCallListener();
                }
    
                @Override
                public void onError(QBResponseException e) {
                    Log.i(TAG, "failed to login: " + e.getMessage());
                    initCallListener();
                }
            });
        }
    }
    
    private boolean isLoggedInToChat(){
        return chatService != null && chatService.isLoggedIn();
    }
    
    private void initCallListener() {
        Log.d(TAG, "init()");
    
        try {
            qbRtcClient = QBRTCClient.getInstance(context);
    
            chatService.getVideoChatWebRTCSignalingManager()
                    .addSignalingManagerListener(new QBVideoChatSignalingManagerListenerImpl());
    
            qbRtcClient.addSessionCallbacksListener(new QBRTCClientSessionCallbacksImpl());
    
            setUpCallClient();
            isInitialized = true;
        } catch (Exception e) {
            Log.i(TAG, e.getMessage());
        }
    
    
    }
    
    public void initActivityClass(Class<? extends Activity> activityClass) {
    
        if (!isInitialized) {
            superInit();
        }
    
        Log.d(TAG, "initActivityClass()");
        this.activityClass = activityClass;
        Log.d("test_crash_1", "initActivityClass(), activityClass = " + activityClass);
    }
    
    public QBRTCSession getCurrentRtcSession() {
        return currentQbRtcSession;
    }
    
    public void initCurrentSession(QBRTCSession qbRtcSession, QBRTCSignalingCallback qbRtcSignalingCallback,
                                   QBRTCSessionConnectionCallbacks qbRtcSessionConnectionCallbacks) {
        this.currentQbRtcSession = qbRtcSession;
        initCurrentSession(qbRtcSignalingCallback, qbRtcSessionConnectionCallbacks);
    }
    
    public void initCurrentSession(QBRTCSignalingCallback qbRtcSignalingCallback,
                                   QBRTCSessionConnectionCallbacks qbRtcSessionConnectionCallbacks) {
        this.currentQbRtcSession.addSignalingCallback(qbRtcSignalingCallback);
        this.currentQbRtcSession.addSessionCallbacksListener(qbRtcSessionConnectionCallbacks);
    }
    
    public void releaseCurrentSession(QBRTCSignalingCallback qbRtcSignalingCallback,
                                      QBRTCSessionConnectionCallbacks qbRtcSessionConnectionCallbacks) {
        if (currentQbRtcSession != null) {
            currentQbRtcSession.removeSignalingCallback(qbRtcSignalingCallback);
            currentQbRtcSession.removeSessionCallbacksListener(qbRtcSessionConnectionCallbacks);
            currentQbRtcSession = null;
        }
    }
    
    private void setUpCallClient() {
        Log.d(TAG, "setUpCallClient()");
    
    
    
        qbRtcClient.prepareToProcessCalls();
    }
    
    private void startCallActivity(QBRTCSession qbRtcSession) {
        QMUser user = QMUserService.getInstance().getUserCache().get((long)qbRtcSession.getSessionDescription().getCallerID());
    
        if (user != null) {
            Log.d(TAG, "startCallActivity(), user = " + user);
            Log.d(TAG, "startCallActivity(), qbRtcSession.getConferenceType() = " + qbRtcSession
                    .getConferenceType());
            Log.d(TAG, "startCallActivity(), qbRtcSession.getSessionDescription() = " + qbRtcSession
                    .getSessionDescription());
    
            List<QBUser> qbUsersList = new ArrayList<>(1);
            qbUsersList.add(UserFriendUtils.createQbUser(user));
            Intent intent = new Intent(context, activityClass);
            intent.putExtra(QBServiceConsts.EXTRA_OPPONENTS, (Serializable) qbUsersList);
            intent.putExtra(QBServiceConsts.EXTRA_START_CONVERSATION_REASON_TYPE,
                    StartConversationReason.INCOME_CALL_FOR_ACCEPTION);
            intent.putExtra(QBServiceConsts.EXTRA_CONFERENCE_TYPE, qbRtcSession.getConferenceType());
            intent.putExtra(QBServiceConsts.EXTRA_SESSION_DESCRIPTION, qbRtcSession.getSessionDescription());
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.getApplicationContext().startActivity(intent);
        } else {
            throw new NullPointerException("user is null!");
        }
    }
    
    
    
    
    public void addRTCSessionUserCallback(QBRTCClientSessionCallbacks qbRtcClientSessionCallbacks) {
        this.qbRtcClientSessionCallbacks = qbRtcClientSessionCallbacks;
    }
    
    public void removeRTCSessionUserCallback() {
        this.qbRtcClientSessionCallbacks = null;
    }
    
    private class QBVideoChatSignalingManagerListenerImpl implements QBVideoChatSignalingManagerListener {
    
        private final String TAG = QBVideoChatSignalingManagerListenerImpl.class.getSimpleName();
    
        @Override
        public void signalingCreated(QBSignaling qbSignaling, boolean createdLocally) {
            if (!createdLocally) {
                qbRtcClient.addSignaling((QBWebRTCSignaling) qbSignaling);
            }
        }
    }
    
    private class QBRTCClientSessionCallbacksImpl implements QBRTCClientSessionCallbacks {
    
        private final String TAG = QBRTCClientSessionCallbacksImpl.class.getSimpleName();
    
        @Override
        public void onReceiveNewSession(QBRTCSession qbRtcSession) {
            Log.d(TAG, "onReceiveNewSession(), qbRtcSession.getSession() = " + qbRtcSession.getSessionID());
            if (currentQbRtcSession != null) {
                Log.d(TAG, "onReceiveNewSession(). Stop new session. Device now is busy");
                if (!qbRtcSession.equals(currentQbRtcSession)) {
                    qbRtcSession.rejectCall(null);
                }
            } else {
                Log.d(TAG, "onReceiveNewSession(). init session.");
                if (activityClass != null) {
    
                    startCallActivity(qbRtcSession);
                    currentQbRtcSession = qbRtcSession;
                }
            }
        }
    
        @Override
        public void onUserNotAnswer(QBRTCSession qbRtcSession, Integer integer) {
            Log.d(TAG, "onUserNotAnswer(), qbRtcSession.getSession() = " + qbRtcSession.getSessionID());
    
            if (qbRtcClientSessionCallbacks != null) {
                qbRtcClientSessionCallbacks.onUserNotAnswer(qbRtcSession, integer);
            }
        }
    
        @Override
        public void onCallRejectByUser(QBRTCSession qbRtcSession, Integer integer, Map<String, String> map) {
            Log.d(TAG, "onCallRejectByUser(), qbRtcSession.getSession() = " + qbRtcSession.getSessionID());
    
            if (qbRtcClientSessionCallbacks != null) {
                qbRtcClientSessionCallbacks.onCallRejectByUser(qbRtcSession, integer, map);
            }
        }
    
        @Override
        public void onCallAcceptByUser(QBRTCSession qbRtcSession, Integer integer, Map<String, String> map) {
            Log.d(TAG, "onCallAcceptByUser(), qbRtcSession.getSession() = " + qbRtcSession.getSessionID());
    
            if (qbRtcClientSessionCallbacks != null) {
                qbRtcClientSessionCallbacks.onCallAcceptByUser(qbRtcSession, integer, map);
            }
        }
    
        @Override
        public void onReceiveHangUpFromUser(QBRTCSession qbrtcSession, Integer integer, Map<String, String> map) {
            Log.d(TAG,
                    "onReceiveHangUpFromUser(), qbRtcSession.getSession() = " + qbrtcSession.getSessionID());
    
            if (qbRtcClientSessionCallbacks != null) {
                qbRtcClientSessionCallbacks.onReceiveHangUpFromUser(qbrtcSession, integer, map);
            }
        }
    
        @Override
        public void onUserNoActions(QBRTCSession qbRtcSession, Integer integer) {
            Log.d(TAG, "onUserNoActions(), qbRtcSession.getSession() = " + qbRtcSession.getSessionID());
    
            if (qbRtcClientSessionCallbacks != null) {
                qbRtcClientSessionCallbacks.onUserNoActions(qbRtcSession, integer);
            }
        }
    
        @Override
        public void onSessionClosed(QBRTCSession qbRtcSession) {
            Log.d(TAG, "onSessionClosed(), qbRtcSession.getSession() = " + qbRtcSession.getSessionID());
    
            if (qbRtcClientSessionCallbacks != null) {
                qbRtcClientSessionCallbacks.onSessionClosed(qbRtcSession);
            }
        }
    
        @Override
        public void onSessionStartClose(QBRTCSession qbRtcSession) {
            Log.d(TAG, "onSessionStartClose(), qbRtcSession.getSession() = " + qbRtcSession.getSessionID());
    
            if (qbRtcClientSessionCallbacks != null) {
                qbRtcClientSessionCallbacks.onSessionStartClose(qbRtcSession);
            }
        }
    }
    
    class CameraErrorHandler implements CameraVideoCapturer.CameraEventsHandler {
    
        @Override
        public void onCameraError(String s) {
            Log.e(TAG, "Error on cams, error = " + s);
        }
    
        @Override
        public void onCameraDisconnected() {
    
        }
    
        @Override
        public void onCameraFreezed(String s) {
            Log.e(TAG, "Camera is frozen " + s);
        }
    
        @Override
        public void onCameraOpening(String i) {
            Log.e(TAG, "Camera opening = " + i);
        }
    
        @Override
        public void onFirstFrameAvailable() {
            Log.e(TAG, "Camera first frame available");
        }
    
        @Override
        public void onCameraClosed() {
            Log.e(TAG, "Camera closed");
        }
    }
    }
    
    
    <<<<<<<<<<<<<<<<<<<<<<<<And this is CallActivity:>>>>>>>>>>>>>>>>>>>>>>
    
    public class CallActivity extends BaseLoggableActivity implements QBRTCClientSessionCallbacks, QBRTCSessionConnectionCallbacks, QBRTCSignalingCallback {
    
    public static final int CALL_ACTIVITY_CLOSE = 1000;
    public static final int CALL_ACTIVITY_CLOSE_WIFI_DISABLED = 1001;
    
    private static final String TAG = CallActivity.class.getSimpleName();
    
    @Bind(R.id.timer_chronometer)
    Chronometer timerChronometer;
    
    private QBRTCTypes.QBConferenceType qbConferenceType;
    private List<QBUser> opponentsList;
    private Runnable showIncomingCallWindowTask;
    private Handler showIncomingCallWindowTaskHandler;
    private BroadcastReceiver wifiStateReceiver;
    private boolean closeByWifiStateAllow = true;
    private String hangUpReason;
    private boolean isInComingCall;
    private boolean isInFront;
    private QBRTCClient qbRtcClient;
    private boolean wifiEnabled = true;
    private RingtonePlayer ringtonePlayer;
    private boolean isStarted = false;
    
    private QBRTCSessionUserCallback qbRtcSessionUserCallback;
    private QBCallChatHelper qbCallChatHelper;
    private StartConversationReason startConversationReason;
    private QBRTCSessionDescription qbRtcSessionDescription;
    private ActionBar actionBar;
    private AudioStreamReceiver audioStreamReceiver;
    private String ACTION_ANSWER_CALL = "action_answer_call";
    private SystemPermissionHelper systemPermissionHelper;
    
    //!MODIFY
    
    public static void start(Activity activity, List<QBUser> qbUsersList, QBRTCTypes.QBConferenceType qbConferenceType,
                             QBRTCSessionDescription qbRtcSessionDescription) {
        Intent intent = new Intent(activity, CallActivity.class);
        intent.putExtra(QBServiceConsts.EXTRA_OPPONENTS, (Serializable) qbUsersList);
        intent.putExtra(QBServiceConsts.EXTRA_CONFERENCE_TYPE, qbConferenceType);
        intent.putExtra(QBServiceConsts.EXTRA_START_CONVERSATION_REASON_TYPE, StartConversationReason.OUTCOME_CALL_MADE);
        intent.putExtra(QBServiceConsts.EXTRA_SESSION_DESCRIPTION, qbRtcSessionDescription);
        intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT| Intent.FLAG_ACTIVITY_CLEAR_TASK);
        activity.startActivityForResult(intent, CALL_ACTIVITY_CLOSE);
    }
    
    @Override
    protected int getContentResId() {
        return R.layout.activity_call;
    }
    
    public void initActionBar() {
        toolbar = (Toolbar) findViewById(R.id.toolbar_call);
        if (toolbar != null) {
            toolbar.setVisibility(View.VISIBLE);
            setSupportActionBar(toolbar);
        }
    
        actionBar = getSupportActionBar();
    
    }
    
    public void setCallActionBarTitle(String title){
        if (actionBar != null) {
            actionBar.setTitle(title);
        }
    }
    
    public void hideCallActionBar(){
        if (actionBar != null) {
            actionBar.hide();
        }
    }
    
    public void showCallActionBar(){
        if (actionBar != null) {
            actionBar.show();
        }
    }
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        App.setFragmentManager(getSupportFragmentManager());
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON|
                WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD|
                WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED|
                WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
    
        canPerformLogout.set(false);
        initFields();
        audioStreamReceiver = new AudioStreamReceiver();
        initWiFiManagerListener();
        if (ACTION_ANSWER_CALL.equals(getIntent().getAction())){
            checkPermissionsAndStartCall(StartConversationReason.INCOME_CALL_FOR_ACCEPTION);
        }
    }
    
    private void initCallFragment() {
        switch (startConversationReason) {
            case INCOME_CALL_FOR_ACCEPTION:
                if (qbRtcSessionDescription != null) {
                    addIncomingCallFragment(qbRtcSessionDescription);
                    isInComingCall = true;
                    initIncomingCallTask();
                }
                break;
            case OUTCOME_CALL_MADE:
                checkPermissionsAndStartCall(StartConversationReason.OUTCOME_CALL_MADE);
                break;
        }
    }
    
    @Override
    protected void onStop() {
        super.onStop();
        unregisterReceiver(wifiStateReceiver);
        unregisterReceiver(audioStreamReceiver);
    }
    
    @Override
    protected void onPause() {
        isInFront = false;
        super.onPause();
    }
    
    @Override
    protected void onResume() {
        isInFront = true;
        super.onResume();
    }
    
    @Override
    protected void onStart() {
        super.onStart();
    
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
        intentFilter.addAction(AudioManager.ACTION_HEADSET_PLUG);
        intentFilter.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED);
        registerReceiver(wifiStateReceiver, intentFilter);
        registerReceiver(audioStreamReceiver, intentFilter);
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.call_menu, menu);
        return true;
    }
    
    @Override
    protected void onDestroy() {
        super.onDestroy();
        opponentsList = null;
        if (qbCallChatHelper != null) {
            qbCallChatHelper.removeRTCSessionUserCallback();
            qbCallChatHelper.releaseCurrentSession(CallActivity.this, CallActivity.this);
        }
    }
    
    @Override
    public void onSuccessSendingPacket(QBSignalingSpec.QBSignalCMD qbSignalCMD, Integer integer) {
    }
    
    @Override
    public void onErrorSendingPacket(QBSignalingSpec.QBSignalCMD qbSignalCMD, Integer userId,
                                     QBRTCSignalException e) {
        ToastUtils.longToast(R.string.dlg_signal_error);
    }
    
    @Override
    public void onReceiveNewSession(final QBRTCSession session) {
        Log.d(TAG, "Session " + session.getSessionID() + " are income");
    }
    
    @Override
    public void onUserNotAnswer(QBRTCSession session, Integer userID) {
        if (!session.equals(getCurrentSession())) {
            return;
        }
    
        if (qbRtcSessionUserCallback != null) {
            qbRtcSessionUserCallback.onUserNotAnswer(session, userID);
        }
    
        ringtonePlayer.stop();
    }
    
    @Override
    public void onCallRejectByUser(QBRTCSession session, Integer userID, Map<String, String> userInfo) {
        if (!session.equals(getCurrentSession())) {
            return;
        }
    
        if (qbRtcSessionUserCallback != null) {
            qbRtcSessionUserCallback.onCallRejectByUser(session, userID, userInfo);
        }
    
        ringtonePlayer.stop();
    }
    
    @Override
    public void onCallAcceptByUser(QBRTCSession session, Integer userId, Map<String, String> userInfo) {
        if (!session.equals(getCurrentSession())) {
            return;
        }
    
        if (qbRtcSessionUserCallback != null) {
            qbRtcSessionUserCallback.onCallAcceptByUser(session, userId, userInfo);
        }
    
        ringtonePlayer.stop();
    }
    
    @Override
    public void onReceiveHangUpFromUser(final QBRTCSession session, final Integer userID, Map<String, String> map) {
        if (session.equals(getCurrentSession())) {
    
            if (qbRtcSessionUserCallback != null) {
                qbRtcSessionUserCallback.onReceiveHangUpFromUser(session, userID);
            }
    
            final String participantName = UserFriendUtils.getUserNameByID(userID, opponentsList);
    
            ToastUtils.longToast("User " + participantName + " " + getString(
                    R.string.call_hung_up) + " conversation");
            finish();
        }
    }
    
    @Override
    public void onUserNoActions(QBRTCSession qbrtcSession, Integer integer) {
        startIncomeCallTimer(0);
    }
    
    @Override
    public void onSessionClosed(final QBRTCSession session) {
        Log.d(TAG, "Session " + session.getSessionID() + " start stop session");
    
        if (session.equals(getCurrentSession())) {
    
            Fragment currentFragment = getCurrentFragment();
            if (isInComingCall) {
                stopIncomeCallTimer();
                if (currentFragment instanceof IncomingCallFragment) {
                    removeFragment();
                    finish();
                }
            }
    
            Log.d(TAG, "Stop session");
    
            if (qbCallChatHelper != null) {
                qbCallChatHelper.releaseCurrentSession(CallActivity.this, CallActivity.this);
            }
    
            stopTimer();
            closeByWifiStateAllow = true;
            finish();
        }
    }
    
    @Override
    public void onSessionStartClose(final QBRTCSession session) {
        session.removeSessionCallbacksListener(CallActivity.this);
        if (currentFragment instanceof ConversationCallFragment && session.equals(getCurrentSession())) {
            ((ConversationCallFragment) currentFragment).actionButtonsEnabled(false);
        }
    }
    
    @Override
    public void onStartConnectToUser(QBRTCSession session, Integer userID) {
    
    }
    
    @Override
    public void onStateChanged(QBRTCSession qbrtcSession, BaseSession.QBRTCSessionState qbrtcSessionState) {
    
    }
    
    @Override
    public void onConnectedToUser(QBRTCSession session, final Integer userID) {
        forbiddenCloseByWifiState();
        if (isInComingCall) {
            stopIncomeCallTimer();
        }
        Log.d(TAG, "onConnectedToUser() is started");
    }
    
    @Override
    public void onConnectionClosedForUser(QBRTCSession session, Integer userID) {
        // Close app after session close of network was disabled
        if (hangUpReason != null && hangUpReason.equals(QBServiceConsts.EXTRA_WIFI_DISABLED)) {
            Intent returnIntent = new Intent();
            setResult(CALL_ACTIVITY_CLOSE_WIFI_DISABLED, returnIntent);
        }
        finish();
    }
    
    @Override
    public void onDisconnectedFromUser(QBRTCSession session, Integer userID) {
    
    }
    
    @Override
    public void onDisconnectedTimeoutFromUser(QBRTCSession session, Integer userID) {
    
    }
    
    @Override
    public void onConnectionFailedWithUser(QBRTCSession session, Integer userID) {
    
    }
    
    @Override
    public void onConnectedToService(QBService service) {
        super.onConnectedToService(service);
        if (qbCallChatHelper == null) {
            qbCallChatHelper = (QBCallChatHelper) service.getHelper(QBService.CALL_CHAT_HELPER);
            systemPermissionHelper = new SystemPermissionHelper(CallActivity.this);
            qbCallChatHelper.addRTCSessionUserCallback(CallActivity.this);
            initCallFragment();
        }
    }
    
    private void initFields() {
        opponentsList = (List<QBUser>) getIntent().getExtras().getSerializable(QBServiceConsts.EXTRA_OPPONENTS);
        qbConferenceType = (QBRTCTypes.QBConferenceType) getIntent().getExtras().getSerializable(QBServiceConsts.EXTRA_CONFERENCE_TYPE);
        startConversationReason = (StartConversationReason) getIntent().getExtras().getSerializable(QBServiceConsts.EXTRA_START_CONVERSATION_REASON_TYPE);
        qbRtcSessionDescription = (QBRTCSessionDescription) getIntent().getExtras().getSerializable(QBServiceConsts.EXTRA_SESSION_DESCRIPTION);
    
        ringtonePlayer = new RingtonePlayer(this, R.raw.beep);
        // Add activity as callback to RTCClient
        qbRtcClient = QBRTCClient.getInstance(this);
    
    }
    
    private void initWiFiManagerListener() {
        wifiStateReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                Log.d(TAG, "WIFI was changed");
                processCurrentWifiState(context);
            }
        };
    }
    
    public QMUser getOpponentAsUserFromDB(final int opponentId){
        /*DataManager dataManager = DataManager.getInstance();
        Friend friend = dataManager.getFriendDataManager().getByUserId(opponentId);*/
    
        //!MODIFY
        Log.i(TAG, "getting friend");
        FriendsHelper friendsHelper = new FriendsHelper(CallActivity.this);
        final QMUser[] qmUser = {friendsHelper.getFriend(Integer.toString(opponentId))};
        return qmUser[0];
    }
    
    private void processCurrentWifiState(Context context) {
        WifiManager wifi = (WifiManager) context.getSystemService(WIFI_SERVICE);
        if (wifiEnabled != wifi.isWifiEnabled()) {
            wifiEnabled = wifi.isWifiEnabled();
            ToastUtils.longToast("Wifi " + (wifiEnabled ? "enabled" : "disabled"));
        }
    }
    
    private void disableConversationFragmentButtons() {
        if (currentFragment instanceof ConversationCallFragment) {
            ((ConversationCallFragment) currentFragment).actionButtonsEnabled(false);
        }
    }
    
    private void initIncomingCallTask() {
        showIncomingCallWindowTaskHandler = new Handler(Looper.myLooper());
        showIncomingCallWindowTask = new Runnable() {
            @Override
            public void run() {
                if (currentFragment instanceof ConversationCallFragment) {
                    disableConversationFragmentButtons();
                    ringtonePlayer.stop();
                    hangUpCurrentSession();
                } else {
                    rejectCurrentSession();
                }
    
                ToastUtils.longToast("Call was stopped by timer");
            }
        };
    }
    
    public void rejectCurrentSession() {
        if (qbCallChatHelper != null && qbCallChatHelper.getCurrentRtcSession() != null) {
            qbCallChatHelper.getCurrentRtcSession().rejectCall(new HashMap<String, String>());
        }
        finish();
    }
    
    public void hangUpCurrentSession() {
        ringtonePlayer.stop();
        if (qbCallChatHelper != null && qbCallChatHelper.getCurrentRtcSession() != null) {
            qbCallChatHelper.getCurrentRtcSession().hangUp(new HashMap<String, String>());
        }
        finish();
    }
    
    private void startIncomeCallTimer(long time) {
        showIncomingCallWindowTaskHandler
                .postAtTime(showIncomingCallWindowTask, SystemClock.uptimeMillis() + time);
    }
    
    private void stopIncomeCallTimer() {
        Log.d(TAG, "stopIncomeCallTimer");
        showIncomingCallWindowTaskHandler.removeCallbacks(showIncomingCallWindowTask);
    }
    
    private void forbiddenCloseByWifiState() {
        closeByWifiStateAllow = false;
    }
    
    private Fragment getCurrentFragment() {
        return getSupportFragmentManager().findFragmentById(R.id.container_fragment);
    }
    
    private void addIncomingCallFragment(QBRTCSessionDescription qbRtcSessionDescription) {
        Log.d(TAG, "QBRTCSession in addIncomingCallFragment is " + qbRtcSessionDescription);
        /*if (isInFront) {
            Fragment fragment = new IncomingCallFragment();
            Bundle bundle = new Bundle();
            bundle.putSerializable(QBServiceConsts.EXTRA_SESSION_DESCRIPTION, qbRtcSessionDescription);
            bundle.putIntegerArrayList(QBServiceConsts.EXTRA_OPPONENTS, new ArrayList<>(qbRtcSessionDescription.getOpponents()));
            bundle.putSerializable(QBServiceConsts.EXTRA_CONFERENCE_TYPE,
                    qbRtcSessionDescription.getConferenceType());
            fragment.setArguments(bundle);
            setCurrentFragment(fragment);
        } else {
            Log.d(TAG, "SKIP addIncomingCallFragment method");
        }*/
        Fragment fragment = new IncomingCallFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable(QBServiceConsts.EXTRA_SESSION_DESCRIPTION, qbRtcSessionDescription);
        bundle.putIntegerArrayList(QBServiceConsts.EXTRA_OPPONENTS, new ArrayList<>(qbRtcSessionDescription.getOpponents()));
        bundle.putSerializable(QBServiceConsts.EXTRA_CONFERENCE_TYPE,
                qbRtcSessionDescription.getConferenceType());
        fragment.setArguments(bundle);
        setCurrentFragment(fragment);
    }
    
    public void checkPermissionsAndStartCall(StartConversationReason startConversationReason) {
        if (systemPermissionHelper.isAllPermissionsGrantedForCallByType(qbConferenceType)) {
            startConversationFragment(startConversationReason);
        } else {
            systemPermissionHelper.requestPermissionsForCallByType(qbConferenceType);
        }
    }
    
    public void addConversationCallFragment() {
        Log.d(TAG, "addConversationCallFragment()");
    
        QBRTCSession newSessionWithOpponents = qbRtcClient.createNewSessionWithOpponents(
                UserFriendUtils.getFriendIdsList(opponentsList), qbConferenceType);
        SettingsUtil.setSettingsStrategy(this, opponentsList);
    
        if (qbCallChatHelper != null) {
            qbCallChatHelper.initCurrentSession(newSessionWithOpponents, this, this);
    
            ConversationCallFragment fragment = ConversationCallFragment
                    .newInstance(opponentsList, opponentsList.get(0).getFullName(), qbConferenceType,
                            StartConversationReason.OUTCOME_CALL_MADE,
                            qbCallChatHelper.getCurrentRtcSession().getSessionID());
    
            setCurrentFragment(fragment);
            ringtonePlayer.play(true);
        } else {
            throw new NullPointerException("qbCallChatHelper is not initialized");
        }
    }
    
    public List<QBUser> getOpponentsList() {
        return opponentsList;
    }
    
    public void setOpponentsList(List<QBUser> qbUsers) {
        this.opponentsList = qbUsers;
    }
    
    public void addConversationFragmentReceiveCall() {
        if (qbCallChatHelper != null) {
            QBRTCSession session = qbCallChatHelper.getCurrentRtcSession();
    
            if (session != null) {
                Integer myId = QBChatService.getInstance().getUser().getId();
                ArrayList<Integer> opponentsWithoutMe = new ArrayList<>(session.getOpponents());
                opponentsWithoutMe.remove(new Integer(myId));
                opponentsWithoutMe.add(session.getCallerID());
    
                ArrayList<QBUser> newOpponents = (ArrayList<QBUser>) UserFriendUtils
                        .getUsersByIDs(opponentsWithoutMe.toArray(new Integer[opponentsWithoutMe.size()]),
                                opponentsList);
                SettingsUtil.setSettingsStrategy(this, newOpponents);
                ConversationCallFragment fragment = ConversationCallFragment.newInstance(newOpponents,
                        UserFriendUtils.getUserNameByID(session.getCallerID(), newOpponents),
                        session.getConferenceType(), StartConversationReason.INCOME_CALL_FOR_ACCEPTION,
                        session.getSessionID());
                // Start conversation fragment
                setCurrentFragment(fragment);
            }
        }
    }
    
    public void startTimer() {
        Log.d(TAG, "startTimer() from CallActivity, timerChronometer = " + timerChronometer);
        if (!isStarted) {
            timerChronometer.setVisibility(View.VISIBLE);
            timerChronometer.setBase(SystemClock.elapsedRealtime());
            timerChronometer.start();
            isStarted = true;
        }
    }
    
    private void stopTimer(){
        if (timerChronometer != null) {
            timerChronometer.stop();
            isStarted = false;
        }
    }
    
    public QBRTCSession getCurrentSession() {
        if (qbCallChatHelper != null) {
            return qbCallChatHelper.getCurrentRtcSession();
        } else {
            return null;
        }
    }
    
    public void addVideoTrackCallbacksListener(QBRTCClientVideoTracksCallbacks videoTracksCallbacks) {
        if (getCurrentSession() != null) {
            getCurrentSession().addVideoTrackCallbacksListener(videoTracksCallbacks);
        }
    }
    
    @Override
    public void onBackPressed() {
        //blocked back button
    }
    
    @Override
    public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
        switch (requestCode) {
            case SystemPermissionHelper.PERMISSIONS_FOR_CALL_REQUEST: {
                if (grantResults.length > 0) {
                    if (!systemPermissionHelper.isAllPermissionsGrantedForCallByType(qbConferenceType)){
                        showToastDeniedPermissions(permissions, grantResults);
                    }
                }
    
                //postDelayed() is temp fix before fixing this bug https://code.google.com/p/android/issues/detail?id=190966
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        startConversationFragment(startConversationReason);
                    }
                }, 500);
            }
        }
    }
    
    private void startConversationFragment(StartConversationReason startConversationReason) {
        if(StartConversationReason.OUTCOME_CALL_MADE.equals(startConversationReason)){
            addConversationCallFragment();
        } else {
            addConversationFragmentReceiveCall();
        }
    }
    
    private void showToastDeniedPermissions(String[] permissions, int[] grantResults) {
        ArrayList<String> deniedPermissions = systemPermissionHelper
                .collectDeniedPermissionsFomResult(permissions, grantResults);
    
        ToastUtils.longToast(
                getString(R.string.denied_permission_message, StringUtils.createCompositeString(deniedPermissions)));
    }
    
    public void addTCClientConnectionCallback(QBRTCSessionConnectionCallbacks clientConnectionCallbacks) {
        if (getCurrentSession() != null) {
            getCurrentSession().addSessionCallbacksListener(clientConnectionCallbacks);
        }
    }
    
    public void removeRTCClientConnectionCallback(QBRTCSessionConnectionCallbacks clientConnectionCallbacks) {
        if (getCurrentSession() != null) {
            getCurrentSession().removeSessionCallbacksListener(clientConnectionCallbacks);
        }
    }
    
    public void addRTCSessionUserCallback(QBRTCSessionUserCallback qbRtcSessionUserCallback) {
        this.qbRtcSessionUserCallback = qbRtcSessionUserCallback;
    }
    
    public void removeRTCSessionUserCallback() {
        this.qbRtcSessionUserCallback = null;
    }
    
    private class AudioStreamReceiver extends BroadcastReceiver {
    
        @Override
        public void onReceive(Context context, Intent intent) {
    
            if (intent.getAction().equals(AudioManager.ACTION_HEADSET_PLUG)) {
                Log.d(TAG, "ACTION_HEADSET_PLUG " + intent.getIntExtra("state", -1));
            } else if (intent.getAction().equals(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED)) {
                Log.d(TAG, "ACTION_SCO_AUDIO_STATE_UPDATED " + intent.getIntExtra("EXTRA_SCO_AUDIO_STATE", -2));
            }
    
            invalidateOptionsMenu();
        }
    }
    
    public interface QBRTCSessionUserCallback {
    
        void onUserNotAnswer(QBRTCSession session, Integer userId);
    
        void onCallRejectByUser(QBRTCSession session, Integer userId, Map<String, String> userInfo);
    
        void onCallAcceptByUser(QBRTCSession session, Integer userId, Map<String, String> userInfo);
    
        void onReceiveHangUpFromUser(QBRTCSession session, Integer userId);
    }

 0 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: