Exemple #1
0
        private void SendNtfIfRequired(Context context)
        {
            var ntfTextBuilder = new IncompleteTaskNtfTextBuilder(App.Current.TaskManager);
            var strs           = ntfTextBuilder.GetEnumerableStrings();

            if (strs.Count > 0)
            {
                var builder = new NotificationCompat.Builder(context)
                              .SetAutoCancel(true) // Dismiss from the notif. area when clicked
                              .SetContentTitle("TODO")
                              .SetSmallIcon(Resource.Drawable.Icon)
                              .SetContentText("TODO"); // The message to display.

                var inboxStyle = new NotificationCompat.InboxStyle();
                foreach (var str in strs)
                {
                    inboxStyle.AddLine(str);
                }
                builder.SetStyle(inboxStyle);

                // Finally, publish the notification:
                NotificationManager notificationManager =
                    (NotificationManager)context.GetSystemService(Context.NotificationService);
                notificationManager.Notify(_notificationId, builder.Build());
            }
        }
        public Builder GetBuilder(Context context, ChannelId channelId)
        {
            Builder builder = new Builder(context);

            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                Channel channel = Channels[(int)channelId];

                if (channel.NotificationChannel == null)
                {
                    // Create a NotificationChannel
                    NotificationChannel notificationChannel = new NotificationChannel(channel.ChannelId, channel.ChannelName, channel.Importance);
                    notificationChannel.Description = " ";
                    notificationChannel.EnableLights(channel.Lights);
                    notificationChannel.EnableVibration(channel.Vibration);
                    notificationChannel.SetBypassDnd(channel.DoNotDisturb);
                    notificationChannel.LockscreenVisibility = channel.Visibility;

                    // Register the new NotificationChannel
                    NotificationManagerCompat notificationManager = GetManager(context);
                    notificationManager.CreateNotificationChannel(notificationChannel);

                    channel.NotificationChannel = notificationChannel;
                }

                builder.SetChannelId(channel.ChannelId);
            }
            return(builder);
        }
        public AndroidNotificationManager ()
        {
            ctx = ServiceContainer.Resolve<Context> ();
            notificationManager = (NotificationManager)ctx.GetSystemService (Context.NotificationService);
            runningBuilder = CreateRunningNotificationBuilder (ctx);
            idleBuilder = CreateIdleNotificationBuilder (ctx);
            propertyTracker = new PropertyChangeTracker ();

            TimeEntryManager = ServiceContainer.Resolve<ActiveTimeEntryManager> ();
            binding = this.SetBinding (() => TimeEntryManager.ActiveTimeEntry).WhenSourceChanges (OnActiveTimeEntryChanged);

            var bus = ServiceContainer.Resolve<MessageBus> ();
            subscriptionSettingChanged = bus.Subscribe<SettingChangedMessage> (OnSettingChanged);
        }
        public AndroidNotificationManager ()
        {
            ctx = ServiceContainer.Resolve<Context> ();
            notificationManager = (NotificationManager)ctx.GetSystemService (Context.NotificationService);
            runningBuilder = CreateRunningNotificationBuilder (ctx);
            idleBuilder = CreateIdleNotificationBuilder (ctx);

            currentTimeEntry = TimeEntryModel.FindRunning ();
            SyncNotification ();

            var bus = ServiceContainer.Resolve<MessageBus> ();
            subscriptionModelChanged = bus.Subscribe<ModelChangedMessage> (OnModelChanged);
            subscriptionSettingChanged = bus.Subscribe<SettingChangedMessage> (OnSettingChanged);
            subscriptionAuthChanged = bus.Subscribe<AuthChangedMessage> (OnAuthChanged);
        }
        public AndroidNotificationManager()
        {
            ctx = ServiceContainer.Resolve <Context> ();
            notificationManager = (NotificationManager)ctx.GetSystemService(Context.NotificationService);
            runningBuilder      = CreateRunningNotificationBuilder(ctx);
            idleBuilder         = CreateIdleNotificationBuilder(ctx);
            propertyTracker     = new PropertyChangeTracker();

            TimeEntryManager = ServiceContainer.Resolve <ActiveTimeEntryManager> ();
            binding          = this.SetBinding(() => TimeEntryManager.ActiveTimeEntry).WhenSourceChanges(OnActiveTimeEntryChanged);

            var bus = ServiceContainer.Resolve <MessageBus> ();

            subscriptionSettingChanged = bus.Subscribe <SettingChangedMessage> (OnSettingChanged);
        }
Exemple #6
0
        public AndroidNotificationManager()
        {
            ctx = ServiceContainer.Resolve <Context> ();
            notificationManager = (NotificationManager)ctx.GetSystemService(Context.NotificationService);
            runningBuilder      = CreateRunningNotificationBuilder(ctx);
            idleBuilder         = CreateIdleNotificationBuilder(ctx);

            currentTimeEntry = TimeEntryModel.FindRunning();
            SyncNotification();

            var bus = ServiceContainer.Resolve <MessageBus> ();

            subscriptionModelChanged   = bus.Subscribe <ModelChangedMessage> (OnModelChanged);
            subscriptionSettingChanged = bus.Subscribe <SettingChangedMessage> (OnSettingChanged);
            subscriptionAuthChanged    = bus.Subscribe <AuthChangedMessage> (OnAuthChanged);
        }
        public AndroidNotificationManager ()
        {
            ctx = ServiceContainer.Resolve<Context> ();
            notificationManager = (NotificationManager)ctx.GetSystemService (Context.NotificationService);
            runningBuilder = CreateRunningNotificationBuilder (ctx);
            idleBuilder = CreateIdleNotificationBuilder (ctx);
            propertyTracker = new PropertyChangeTracker ();

            timeEntryManager = ServiceContainer.Resolve<ActiveTimeEntryManager> ();
            timeEntryManager.PropertyChanged += OnActiveTimeEntryManagerPropertyChanged;

            var bus = ServiceContainer.Resolve<MessageBus> ();
            subscriptionSettingChanged = bus.Subscribe<SettingChangedMessage> (OnSettingChanged);

            SyncRunningModel ();
            SyncNotification ();
        }
        public void NotifyNewChapters(Context context, List <Chapter> chapters)
        {
            if (chapters.Count < 1)
            {
                return;
            }

            Builder builder = GetBuilder(context, ChannelId.NewChapter);

            builder.SetAutoCancel(true);
            builder.SetNumber(4);
            builder.SetOnlyAlertOnce(true);
            builder.SetContentTitle("1 New Chapter");
            builder.SetContentText(chapters[0].Title);

            Intent intent = new Intent(Intent.ActionView);

            intent.SetData(Uri.Parse(chapters[0].URL));
            intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask);
            PendingIntent pendingIntent = PendingIntent.GetActivity(context, (int)ChannelId.NewChapter, intent, PendingIntentFlags.OneShot);

            builder.SetContentIntent(pendingIntent);

            if (chapters.Count > 1)
            {
                builder.SetContentTitle($"{chapters.Count} New Chapters");
                builder.SetSubText($"and {chapters.Count - 1} more");

                var inboxStyle = new Notification.InboxStyle(GetBuilder(context, ChannelId.NewChapter));
                inboxStyle.SetBigContentTitle($"{chapters.Count} New Chapters");

                foreach (Chapter chapter in chapters)
                {
                    inboxStyle.AddLine(chapter.Title);
                }

                builder.SetStyle(inboxStyle);
            }
            //Bitmap icon = BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.new_chapter_icon);
            builder.SetSmallIcon(Resource.Drawable.new_chapter_icon);

            NotificationManagerCompat notificationManager = GetManager(context);

            notificationManager.Notify((int)ChannelId.NewChapter, builder.Build());
        }
        public AndroidNotificationManager()
        {
            ctx = ServiceContainer.Resolve <Context> ();
            notificationManager = (NotificationManager)ctx.GetSystemService(Context.NotificationService);
            runningBuilder      = CreateRunningNotificationBuilder(ctx);
            idleBuilder         = CreateIdleNotificationBuilder(ctx);
            propertyTracker     = new PropertyChangeTracker();

            timeEntryManager = ServiceContainer.Resolve <ActiveTimeEntryManager> ();
            timeEntryManager.PropertyChanged += OnActiveTimeEntryManagerPropertyChanged;

            var bus = ServiceContainer.Resolve <MessageBus> ();

            subscriptionSettingChanged = bus.Subscribe <SettingChangedMessage> (OnSettingChanged);

            SyncRunningModel();
            SyncNotification();
        }
Exemple #10
0
        // Handler for button click events.
        private void ButtonOnClick(object sender, EventArgs eventArgs)
        {
            // Pass the current button press count value to the next activity:
            Bundle valuesForActivity = new Bundle();

            valuesForActivity.PutInt("count", count);

            // When the user clicks the notification, SecondActivity will start up.
            Intent resultIntent = new Intent(this, typeof(SecondActivity));

            // Pass some values to SecondActivity:
            resultIntent.PutExtras(valuesForActivity);

            // Construct a back stack for cross-task navigation:
            TaskStackBuilder stackBuilder = TaskStackBuilder.Create(this);

            stackBuilder.AddParentStack(Class.FromType(typeof(SecondActivity)));
            stackBuilder.AddNextIntent(resultIntent);

            // Create the PendingIntent with the back stack:
            PendingIntent resultPendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);

            // Build the notification:
            NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                                                 .SetAutoCancel(true)                                                             // Dismiss the notification from the notification area when the user clicks on it
                                                 .SetContentIntent(resultPendingIntent)                                           // Start up this activity when the user clicks the intent.
                                                 .SetContentTitle("Button Clicked")                                               // Set the title
                                                 .SetNumber(count)                                                                // Display the count in the Content Info
                                                 .SetSmallIcon(Resource.Drawable.ic_stat_button_click)                            // This is the icon to display
                                                 .SetContentText(String.Format("The button has been clicked {0} times.", count)); // the message to display.

            // Finally, publish the notification:
            NotificationManager notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);

            notificationManager.Notify(ButtonClickNotificationId, builder.Build());

            // Increment the button press count:
            count++;
        }
        // Handler for button click events.
        private void ButtonOnClick(object sender, EventArgs eventArgs)
        {
            // Pass the current button press count value to the next activity:
            Bundle valuesForActivity = new Bundle();
            valuesForActivity.PutInt("count", count);

            // When the user clicks the notification, SecondActivity will start up.
            Intent resultIntent = new Intent(this, typeof(SecondActivity));

            // Pass some values to SecondActivity:
            resultIntent.PutExtras(valuesForActivity); 

            // Construct a back stack for cross-task navigation:
            TaskStackBuilder stackBuilder = TaskStackBuilder.Create(this);
            stackBuilder.AddParentStack(Class.FromType(typeof(SecondActivity)));
            stackBuilder.AddNextIntent(resultIntent);

            // Create the PendingIntent with the back stack:            
            PendingIntent resultPendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);



            // Build the notification:
			NotificationCompat.Builder builder = new NotificationCompat.Builder (this)
                .SetAutoCancel (true)                    // Dismiss the notification from the notification area when the user clicks on it
                .SetContentIntent (resultPendingIntent)  // Start up this activity when the user clicks the intent.
                .SetContentTitle ("Button Clicked")      // Set the title
                .SetNumber (count)                       // Display the count in the Content Info
                .SetSmallIcon (Resource.Drawable.ic_stat_button_click) // This is the icon to display
				.SetContentText (String.Format ("The button has been clicked {0} times.", count)); // the message to display.

			
            // Finally, publish the notification:
            NotificationManager notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);
            notificationManager.Notify(ButtonClickNotificationId, builder.Build());

            // Increment the button press count:
            count++;
        }
        void SendNotification()
        {
            NotificationCompat.Builder builder =
                new NotificationCompat.Builder(this)
                .SetContentTitle("Beacon Reference Application")
                .SetContentText("An beacon is nearby.")
                .SetSmallIcon(Resource.Mipmap.Icon);

            var stackBuilder = TaskStackBuilder.Create(this);

            stackBuilder.AddNextIntent(new Intent(this, typeof(MonitoringActivity)));
            PendingIntent resultPendingIntent =
                stackBuilder.GetPendingIntent(
                    0,
                    PendingIntentFlags.UpdateCurrent
                    );

            builder.SetContentIntent(resultPendingIntent);
            NotificationManager notificationManager =
                (NotificationManager)this.GetSystemService(Context.NotificationService);

            notificationManager.Notify(1, builder.Build());
        }
Exemple #13
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource (strings are loaded from Recources -> values -> Strings.xml)
            SetContentView(Resource.Layout.Home);

            // find and set the controls, so it can be used in the code
            buttonConnect           = FindViewById <Button>(Resource.Id.buttonConnect);
            textViewTimerStateValue = FindViewById <TextView>(Resource.Id.textViewTimerStateValue);
            textViewServerConnect   = FindViewById <TextView>(Resource.Id.textViewServerConnect);
            textViewSensorValue1    = FindViewById <TextView>(Resource.Id.textViewSensorValue1);
            textViewSensorValue2    = FindViewById <TextView>(Resource.Id.textViewSensorValue2);
            textViewSensorValue3    = FindViewById <TextView>(Resource.Id.textViewSensorValue3);
            textViewSensorValue4    = FindViewById <TextView>(Resource.Id.textViewSensorValue4);
            editTextIPAddress       = FindViewById <EditText>(Resource.Id.editTextIPAddress);
            editTextIPPort          = FindViewById <EditText>(Resource.Id.editTextIPPort);
            switchSwitch1           = FindViewById <Switch>(Resource.Id.switchSwitch1);
            switchSwitch2           = FindViewById <Switch>(Resource.Id.switchSwitch2);
            switchSwitch3           = FindViewById <Switch>(Resource.Id.switchSwitch3);
            vib = (Vibrator)this.GetSystemService(VibratorService);

            spinner = FindViewById <Spinner>(Resource.Id.spinner);

            spinner.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs>(spinner_ItemSelected);
            var adapter = ArrayAdapter.CreateFromResource(
                this, Resource.Array.planets_array, Android.Resource.Layout.SimpleSpinnerItem);

            adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
            spinner.Adapter = adapter;

            Intent notificationIntent = new Intent(this, typeof(MainActivity));

            TaskStackBuilder stackBuilder = TaskStackBuilder.Create(this);

            stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(MainActivity)));
            stackBuilder.AddNextIntent(notificationIntent);

            PendingIntent pendingNotificationIntent =
                stackBuilder.GetPendingIntent(0, PendingIntentFlags.UpdateCurrent);

            builder = new NotificationCompat.Builder(this)
                      .SetAutoCancel(true)
                      .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
                      .SetContentIntent(pendingNotificationIntent)
                      .SetSmallIcon(Resource.Drawable.notificationicon)
                      .SetContentTitle("Movement Detected")
                      .SetPriority(2)
                      .SetOnlyAlertOnce(true);

            notificationManager =
                (NotificationManager)GetSystemService(NotificationService);

            UpdateConnectionState(4, "Disconnected");

            // Init commandlist, scheduled by socket timer
            commandList.Add(new Tuple <string, TextView>("r", textViewSensorValue1));
            commandList.Add(new Tuple <string, TextView>("c", textViewSensorValue2));
            commandList.Add(new Tuple <string, TextView>("b", textViewSensorValue3));
            commandList.Add(new Tuple <string, TextView>("p", textViewSensorValue4));

            this.Title = this.Title + " (timer sockets)";

            // timer object, running clock
            timerClock = new System.Timers.Timer()
            {
                Interval = 1000, Enabled = true
            };                                                                          // Interval >= 1000
            timerClock.Elapsed += (obj, args) =>
            {
                RunOnUiThread(() => { textViewTimerStateValue.Text = DateTime.Now.ToString("h:mm:ss"); });
            };

            // timer object, check Arduino state
            // Only one command can be serviced in an timer tick, schedule from list
            timerSockets = new System.Timers.Timer()
            {
                Interval = timerDelay, Enabled = false
            };                                                                                   // Interval >= 750
            timerSockets.Elapsed += (obj, args) =>
            {
                //RunOnUiThread(() =>
                //{
                if (socket != null) // only if socket exists
                {
                    // Send a command to the Arduino server on every tick (loop though list)
                    UpdateGUI(executeCommand(commandList[listIndex].Item1), commandList[listIndex].Item2);  //e.g. UpdateGUI(executeCommand("s"), textViewChangePinStateValue);
                    if (++listIndex >= commandList.Count)
                    {
                        listIndex = 0;
                    }
                }
                else
                {
                    timerSockets.Enabled = false;   // If socket broken -> disable timer
                }
                //});
            };

            //Add the "Connect" button handler.
            if (buttonConnect != null)  // if button exists
            {
                buttonConnect.Click += (sender, e) =>
                {
                    //Validate the user input (IP address and port)
                    if (CheckValidIpAddress(editTextIPAddress.Text) && CheckValidPort(editTextIPPort.Text))
                    {
                        ConnectSocket(editTextIPAddress.Text, editTextIPPort.Text);
                    }
                    else
                    {
                        UpdateConnectionState(3, "Please check IP");
                    }
                };
            }

            if (switchSwitch1 != null)
            {
                switchSwitch1.Click += (sender, e) =>
                {
                    socket.Send(Encoding.ASCII.GetBytes("1"));
                };
            }
            if (switchSwitch2 != null)
            {
                switchSwitch2.Click += (sender, e) =>
                {
                    socket.Send(Encoding.ASCII.GetBytes("2"));
                };
            }
            if (switchSwitch3 != null)
            {
                switchSwitch3.Click += (sender, e) =>
                {
                    socket.Send(Encoding.ASCII.GetBytes("3"));
                };
            }
        }