//Checks to see if the SDK is connected to Layer and whether a user is authenticated
        //The respective callbacks are executed in MyConnectionListener and MyAuthenticationListener
        private void _LoadLayerClient()
        {
            // Check if Sample App is using a valid app ID.
            if (_IsValidAppID())
            {
                if (layerClient == null)
                {
                    //Used for debugging purposes ONLY. DO NOT include this option in Production Builds.
                    LayerClient.SetLoggingEnabled(this.ApplicationContext, true);

                    // Initializes a LayerClient object with the Google Project Number
                    LayerClient.Options options = new LayerClient.Options();

                    //Sets the GCM sender id allowing for push notifications
                    options.InvokeGoogleCloudMessagingSenderId(GCM_PROJECT_NUMBER);

                    //By default, only unread messages are synced after a user is authenticated, but you
                    // can change that behavior to all messages or just the last message in a conversation
                    options.InvokeHistoricSyncPolicy(LayerClient.Options.HistoricSyncPolicy.AllMessages);


                    layerClient = LayerClient.NewInstance(this, LAYER_APP_ID, options);

                    //Register the connection and authentication listeners
                    layerClient.RegisterConnectionListener(connectionListener);
                    layerClient.RegisterAuthenticationListener(authenticationListener);
                }

                //Check the current state of the SDK. The client must be CONNECTED and the user must
                // be AUTHENTICATED in order to send and receive messages. Note: it is possible to be
                // authenticated, but not connected, and vice versa, so it is a best practice to check
                // both states when your app launches or comes to the foreground.
                if (!layerClient.IsConnected)
                {
                    //If Layer is not connected, make sure we connect in order to send/receive messages.
                    // MyConnectionListener.java handles the callbacks associated with Connection, and
                    // will start the Authentication process once the connection is established
                    layerClient.Connect();
                }
                else if (!layerClient.IsAuthenticated)
                {
                    //If the client is already connected, try to authenticate a user on this device.
                    // MyAuthenticationListener.java handles the callbacks associated with Authentication
                    // and will start the Conversation View once the user is authenticated
                    layerClient.Authenticate();
                }
                else
                {
                    // If the client is to Layer and the user is authenticated, start the Conversation
                    // View. This will be called when the app moves from the background to the foreground,
                    // for example.
                    OnUserAuthenticated();
                }
            }
        }
        //==============================================================================================
        // Application Overrides
        //==============================================================================================

        public override void OnCreate()
        {
            base.OnCreate();

            // Enable verbose logging in debug builds
            if (BuildConfig.DEBUG)
            {
                Com.Layer.Atlas.Util.Log.SetAlwaysLoggable(true);
                Messenger.Util.Log.SetAlwaysLoggable(true);
                LayerClient.SetLoggingEnabled(this, true);
            }

            // Allow the LayerClient to track app state
            LayerClient.ApplicationCreated(this);

            sInstance = this;
        }
Example #3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // View cache
            mAvatar                = FindViewById <AtlasAvatar>(Resource.Id.avatar);
            mUserName              = FindViewById <TextView>(Resource.Id.user_name);
            mUserState             = FindViewById <TextView>(Resource.Id.user_state);
            mLogoutButton          = FindViewById <Button>(Resource.Id.logout_button);
            mShowNotifications     = FindViewById <Switch>(Resource.Id.show_notifications_switch);
            mVerboseLogging        = FindViewById <Switch>(Resource.Id.logging_switch);
            mAppVersion            = FindViewById <TextView>(Resource.Id.app_version);
            mAtlasVersion          = FindViewById <TextView>(Resource.Id.atlas_version);
            mLayerVersion          = FindViewById <TextView>(Resource.Id.layer_version);
            mAndroidVersion        = FindViewById <TextView>(Resource.Id.android_version);
            mUserId                = FindViewById <TextView>(Resource.Id.user_id);
            mConversationCount     = FindViewById <TextView>(Resource.Id.conversation_count);
            mMessageCount          = FindViewById <TextView>(Resource.Id.message_count);
            mUnreadMessageCount    = FindViewById <TextView>(Resource.Id.unread_message_count);
            mDiskUtilization       = FindViewById <TextView>(Resource.Id.disk_utilization);
            mDiskAllowance         = FindViewById <TextView>(Resource.Id.disk_allowance);
            mAutoDownloadMimeTypes = FindViewById <TextView>(Resource.Id.auto_download_mime_types);
            mAvatar.Init(GetParticipantProvider(), GetPicasso());

            // Long-click copy-to-clipboard
            mUserName.SetOnLongClickListener(this);
            mUserState.SetOnLongClickListener(this);
            mAppVersion.SetOnLongClickListener(this);
            mAndroidVersion.SetOnLongClickListener(this);
            mAtlasVersion.SetOnLongClickListener(this);
            mLayerVersion.SetOnLongClickListener(this);
            mUserId.SetOnLongClickListener(this);
            mConversationCount.SetOnLongClickListener(this);
            mMessageCount.SetOnLongClickListener(this);
            mUnreadMessageCount.SetOnLongClickListener(this);
            mDiskUtilization.SetOnLongClickListener(this);
            mDiskAllowance.SetOnLongClickListener(this);
            mAutoDownloadMimeTypes.SetOnLongClickListener(this);

            // Buttons and switches
            mLogoutButton.Click += (sender, args) =>
            {
                SetEnabled(false);
                new AlertDialog.Builder(this)
                .SetCancelable(false)
                .SetMessage(Resource.String.alert_message_logout)
                .SetPositiveButton(Resource.String.alert_button_logout, (sender_, args_) =>
                {
                    if (Util.Log.IsLoggable(Util.Log.VERBOSE))
                    {
                        Util.Log.v("Deauthenticating");
                    }
                    ((IDialogInterface)sender_).Dismiss();
                    ProgressDialog progressDialog = new ProgressDialog(this);
                    progressDialog.SetMessage(Resources.GetString(Resource.String.alert_dialog_logout));
                    progressDialog.SetCancelable(false);
                    progressDialog.Show();
                    App.Deauthenticate(new AtlasUtilDeauthenticationCallback(this, progressDialog));
                })
                .SetNegativeButton(Resource.String.alert_button_cancel, (sender_, args_) =>
                {
                    ((IDialogInterface)sender_).Dismiss();
                    SetEnabled(true);
                })
                .Show();
            };

            mShowNotifications.CheckedChange += (sender, args) =>
            {
                PushNotificationReceiver.GetNotifications(this).SetEnabled(args.IsChecked);
            };

            mVerboseLogging.CheckedChange += (sender, args) =>
            {
                LayerClient.SetLoggingEnabled(this, args.IsChecked);
                Atlas.Util.Log.SetAlwaysLoggable(args.IsChecked);
                Util.Log.SetAlwaysLoggable(args.IsChecked);
            };
        }