Search in sources :

Example 1 with ReachabilityReceiver

use of com.voipgrid.vialer.reachability.ReachabilityReceiver in project vialer-android by VoIPGRID.

the class DialerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_dialer);
    // Set the AnalyticsHelper
    mAnalyticsHelper = new AnalyticsHelper(((AnalyticsApplication) getApplication()).getDefaultTracker());
    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    mJsonStorage = new JsonStorage(this);
    mConnectivityHelper = ConnectivityHelper.get(this);
    mReachabilityReceiver = new ReachabilityReceiver(this);
    mContactsListView = (ListView) findViewById(R.id.list_view);
    mEmptyView = (TextView) findViewById(R.id.message);
    mEmptyView.setText("");
    // This should be called before setupContactParts.
    setupKeypad();
    Intent intent = getIntent();
    String type = intent.getType();
    // Sadly HTC fails to include the mime-type in the intent in 4.4.2.
    Uri contactUri = intent.getData();
    mHasPermission = ContactsPermission.hasPermission(this);
    mAskForPermission = true;
    // Check for contact permissions before doing contact related work.
    if (mHasPermission) {
        // Handling this intent is only needed when we have contact permissions.
        // This should be called after setupKeyPad.
        setupContactParts();
        /**
         * The app added a "Vialer call <number>" to the native contacts app. clicking this
         * opens the app with the appname's profile and the data necessary for opening the app.
         */
        if ((!TextUtils.isEmpty(type) && type.equals(getString(R.string.profile_mimetype))) || contactUri != null) {
            // presses call with vialer in a contact.
            if (!mJsonStorage.has(SystemUser.class)) {
                startActivity(new Intent(this, SetupActivity.class));
                finish();
            }
            Cursor cursor = getContentResolver().query(contactUri, new String[] { ContactsContract.CommonDataKinds.StructuredName.PHONETIC_NAME, ContactsContract.Data.DATA3 }, null, null, null);
            cursor.moveToFirst();
            String number = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.DATA3));
            mNumberInputView.setNumber(number);
            cursor.close();
        }
    } else {
        // Set the empty view for the contact list to inform the user this functionality will
        // not work.
        mEmptyView.setText(getString(R.string.permission_contact_dialer_list_message));
        mContactsListView.setEmptyView(mEmptyView);
    }
    // Make sure there is no keyboard popping up when pasting in the dialer input field.
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
}
Also used : ReachabilityReceiver(com.voipgrid.vialer.reachability.ReachabilityReceiver) AnalyticsApplication(com.voipgrid.vialer.analytics.AnalyticsApplication) SetupActivity(com.voipgrid.vialer.onboarding.SetupActivity) SystemUser(com.voipgrid.vialer.api.models.SystemUser) Intent(android.content.Intent) JsonStorage(com.voipgrid.vialer.util.JsonStorage) Cursor(android.database.Cursor) Uri(android.net.Uri) AnalyticsHelper(com.voipgrid.vialer.analytics.AnalyticsHelper)

Example 2 with ReachabilityReceiver

use of com.voipgrid.vialer.reachability.ReachabilityReceiver in project vialer-android by VoIPGRID.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle startBundle = getIntent().getExtras();
    if (startBundle != null) {
        boolean onBoot = startBundle.getBoolean("OnBoot");
        if (onBoot) {
            finish();
            return;
        }
    }
    JsonStorage jsonStorage = new JsonStorage(this);
    ConnectivityHelper connectivityHelper = ConnectivityHelper.get(this);
    Boolean hasSystemUser = jsonStorage.has(SystemUser.class);
    SystemUser systemUser = (SystemUser) jsonStorage.get(SystemUser.class);
    // on boarding part where the mobile number needs to be configured.
    if (!hasSystemUser) {
        // Start on boarding flow.
        startActivity(new Intent(this, SetupActivity.class));
        finish();
        return;
    } else if (UpdateHelper.requiresUpdate(this)) {
        Intent intent = new Intent(this, UpdateActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
        finish();
        return;
    } else if (systemUser.getMobileNumber() == null) {
        Intent intent = new Intent(this, SetupActivity.class);
        Bundle bundle = new Bundle();
        bundle.putInt("fragment", R.id.fragment_account);
        bundle.putString("activity", AccountFragment.class.getSimpleName());
        intent.putExtras(bundle);
        startActivity(intent);
        finish();
        return;
    } else if (connectivityHelper.hasNetworkConnection()) {
        // Update SystemUser and PhoneAccount on background thread.
        new PhoneAccountHelper(this).executeUpdatePhoneAccountTask();
    }
    if (SyncUtils.requiresFullContactSync(this)) {
        SyncUtils.requestContactSync(this);
    } else {
        startContactObserverService();
    }
    SyncUtils.setPeriodicSync(this);
    setContentView(R.layout.activity_main);
    // Set the Toolbar to use as ActionBar.
    setActionBar(R.id.action_bar);
    setNavigationDrawer(R.id.drawer_layout);
    // Set tabs.
    setupTabs();
    FloatingActionButton openDialerFab = findViewById(R.id.floating_action_button);
    openDialerFab.setOnClickListener(this);
    requestCounter = 0;
    mReachabilityReceiver = new ReachabilityReceiver(this);
}
Also used : ConnectivityHelper(com.voipgrid.vialer.util.ConnectivityHelper) Bundle(android.os.Bundle) UpdateActivity(com.voipgrid.vialer.util.UpdateActivity) Intent(android.content.Intent) ReachabilityReceiver(com.voipgrid.vialer.reachability.ReachabilityReceiver) SetupActivity(com.voipgrid.vialer.onboarding.SetupActivity) PhoneAccountHelper(com.voipgrid.vialer.util.PhoneAccountHelper) SystemUser(com.voipgrid.vialer.api.models.SystemUser) FloatingActionButton(android.support.design.widget.FloatingActionButton) JsonStorage(com.voipgrid.vialer.util.JsonStorage) AccountFragment(com.voipgrid.vialer.onboarding.AccountFragment)

Aggregations

Intent (android.content.Intent)2 SystemUser (com.voipgrid.vialer.api.models.SystemUser)2 SetupActivity (com.voipgrid.vialer.onboarding.SetupActivity)2 ReachabilityReceiver (com.voipgrid.vialer.reachability.ReachabilityReceiver)2 JsonStorage (com.voipgrid.vialer.util.JsonStorage)2 Cursor (android.database.Cursor)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 AnalyticsApplication (com.voipgrid.vialer.analytics.AnalyticsApplication)1 AnalyticsHelper (com.voipgrid.vialer.analytics.AnalyticsHelper)1 AccountFragment (com.voipgrid.vialer.onboarding.AccountFragment)1 ConnectivityHelper (com.voipgrid.vialer.util.ConnectivityHelper)1 PhoneAccountHelper (com.voipgrid.vialer.util.PhoneAccountHelper)1 UpdateActivity (com.voipgrid.vialer.util.UpdateActivity)1