Search in sources :

Example 1 with ProximitySensorHelper

use of com.voipgrid.vialer.util.ProximitySensorHelper in project vialer-android by VoIPGRID.

the class CallActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mRemoteLogger = new RemoteLogger(CallActivity.class).enableConsoleLogging();
    mRemoteLogger.d("onCreate");
    // Check if we have permission to use the microphone. If not, request it.
    if (!MicrophonePermission.hasPermission(this)) {
        MicrophonePermission.askForPermission(this);
    }
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
    setContentView(R.layout.activity_call);
    // Fetch a broadcast manager for communication.
    mBroadcastManager = LocalBroadcastManager.getInstance(this);
    mNotificationHelper = NotificationHelper.getInstance(this);
    // Set the AnalyticsHelper.
    mAnalyticsHelper = new AnalyticsHelper(((AnalyticsApplication) getApplication()).getDefaultTracker());
    mMediaManager = MediaManager.init(this, this, this);
    mProximityHelper = new ProximitySensorHelper(this, this, findViewById(R.id.screen_off));
    // Fetch a broadcast manager for communication to the sip service
    mBroadcastManager = LocalBroadcastManager.getInstance(this);
    mStateView = (TextView) findViewById(R.id.state_text_view);
    mCallDurationView = (TextView) findViewById(R.id.duration_text_view);
    mConnected = false;
    onCallStatesUpdateButtons(SERVICE_STOPPED);
    Intent intent = getIntent();
    // Get the intent to see if it's an outgoing or an incoming call.
    mType = intent.getType();
    if (mType.equals(TYPE_INCOMING_CALL) || mType.equals(TYPE_OUTGOING_CALL)) {
        // Update the textView with a number URI.
        mPhoneNumberToDisplay = intent.getStringExtra(PHONE_NUMBER);
        mCallerIdToDisplay = intent.getStringExtra(CONTACT_NAME);
        displayCallInfo();
        mIsIncomingCall = mType.equals(TYPE_INCOMING_CALL);
        Boolean openedFromNotification = intent.getBooleanExtra(NotificationHelper.TAG, false);
        if (openedFromNotification && !mIsIncomingCall) {
            mNotificationId = mNotificationHelper.displayCallProgressNotification(getCallerInfo(), getString(R.string.callnotification_active_call), TYPE_CONNECTED_CALL, mCallerIdToDisplay, mPhoneNumberToDisplay, NotificationHelper.mCallNotifyId);
            toggleCallStateButtonVisibility(TYPE_CONNECTED_CALL);
            // Keep timer running for as long as possible.
            mCallHandler.postDelayed(mCallDurationRunnable, 1000);
            mCallDurationView.setVisibility(View.VISIBLE);
        } else {
            toggleCallStateButtonVisibility(mType);
            if (mIsIncomingCall) {
                mRemoteLogger.d("inComingCall");
                mNotificationHelper.removeAllNotifications();
                mNotificationId = mNotificationHelper.displayCallProgressNotification(getCallerInfo(), getString(R.string.callnotification_incoming_call), mType, mCallerIdToDisplay, mPhoneNumberToDisplay, NotificationHelper.mCallNotifyId);
                // Ringing event.
                mAnalyticsHelper.sendEvent(getString(R.string.analytics_event_category_call), getString(R.string.analytics_event_action_inbound), getString(R.string.analytics_event_label_ringing));
                if (!ReadExternalStoragePermission.hasPermission(this)) {
                    ReadExternalStoragePermission.askForPermission(this);
                }
                mIncomingCallIsRinging = true;
                mMediaManager.startIncomingCallRinger();
            } else {
                mRemoteLogger.d("outgoingCall");
                mNotificationId = mNotificationHelper.displayCallProgressNotification(getCallerInfo(), getString(R.string.callnotification_dialing), mType, mCallerIdToDisplay, mPhoneNumberToDisplay, NotificationHelper.mCallNotifyId);
            }
        }
        mMediaManager.callStarted();
    }
    mProximityHelper.startSensor();
}
Also used : AnalyticsApplication(com.voipgrid.vialer.analytics.AnalyticsApplication) Intent(android.content.Intent) RemoteLogger(com.voipgrid.vialer.logging.RemoteLogger) ProximitySensorHelper(com.voipgrid.vialer.util.ProximitySensorHelper) AnalyticsHelper(com.voipgrid.vialer.analytics.AnalyticsHelper)

Aggregations

Intent (android.content.Intent)1 AnalyticsApplication (com.voipgrid.vialer.analytics.AnalyticsApplication)1 AnalyticsHelper (com.voipgrid.vialer.analytics.AnalyticsHelper)1 RemoteLogger (com.voipgrid.vialer.logging.RemoteLogger)1 ProximitySensorHelper (com.voipgrid.vialer.util.ProximitySensorHelper)1