예제 #1
0
        private static ICursor CreateCursor(Context context, string selection, string[] param)
        {
            var sortOrder = PreferencesUtility.GetInstance(context).GetArtistSortOrder();
            var uri       = Artists.ExternalContentUri;

            return(context.ContentResolver.Query(uri, PROJECTION, selection, param, sortOrder));
        }
예제 #2
0
        private static ICursor CreateCursor(Context context, long artistId)
        {
            var sortOrder = PreferencesUtility.GetInstance(context).GetArtistSongSortOrder();
            var uri       = Media.ExternalContentUri;
            var selection = "is_music=1 AND title != '' AND artist_id=" + artistId;

            return(context.ContentResolver.Query(uri, PROJECTION, selection, null, sortOrder));
        }
예제 #3
0
        private static ICursor CreateCursor(Context context, string selection, string[] param)
        {
            var albumSortOrder = PreferencesUtility.GetInstance(context).GetAlbumSortOrder();
            var cursor         = context.ContentResolver.Query(Albums.ExternalContentUri,
                                                               PROJECTION, selection, param, albumSortOrder);

            return(cursor);
        }
예제 #4
0
        private static ICursor CreateCursor(Context context)
        {
            var limitAddedTime = Java.Lang.JavaSystem.CurrentTimeMillis() / 1000 - SECONDS_IN_WEEK;
            var cutoff         = PreferencesUtility.GetInstance(context).GetLastAddedCutoff();

            if (limitAddedTime > cutoff)
            {
                cutoff = limitAddedTime;
                PreferencesUtility.GetInstance(context).SetLastAddedCutoff(cutoff);
            }

            var selection = $"{AudioColumns.IsMusic} = 1 AND {AudioColumns.Title} != '' " +
                            $"AND {AudioColumns.DateAdded} > {cutoff}";

            return(context.ContentResolver.Query(Media.ExternalContentUri, PROJECTION, selection,
                                                 null, $"{AudioColumns.DateAdded} DESC"));
        }
예제 #5
0
 public override void OnCreate(Bundle savedInstanceState)
 {
     base.OnCreate(savedInstanceState);
     _preferences = PreferencesUtility.GetInstance(Activity);
 }
        public static ICursor CreateSongCursor(Context context, string selection, string[] param)
        {
            var songSortOrder = PreferencesUtility.GetInstance(context).GetSongSortOrder();

            return(CreateSongCursor(context, selection, param, songSortOrder));
        }
        public override void OnReceive(Context context, Intent intent)
        {
            var intentAction = intent.Action;

            if (intentAction.Equals(AudioManager.ActionAudioBecomingNoisy))
            {
                if (PreferencesUtility.GetInstance(context).PauseOnDetach())
                {
                    StartTheService(context, MusicService.CMDPAUSE);
                }
            }
            else if (intentAction.Equals(Intent.ActionMediaButton))
            {
                if (!(intent.GetParcelableExtra(Intent.ExtraKeyEvent) is KeyEvent key))
                {
                    return;
                }
                var keycode   = key.KeyCode;
                var action    = key.Action;
                var eventTime = key.EventTime;
                var cmd       = "";
                switch (keycode)
                {
                case Keycode.MediaStop:
                    cmd = MusicService.CMDSTOP;
                    break;

                case Keycode.Headsethook:
                case Keycode.MediaPlayPause:
                    cmd = MusicService.CMDTOGGLEPAUSE;
                    break;

                case Keycode.MediaNext:
                    cmd = MusicService.CMDNEXT;
                    break;

                case Keycode.MediaPrevious:
                    cmd = MusicService.CMDPREVIOUS;
                    break;

                case Keycode.MediaPlay:
                    cmd = MusicService.CMDPLAY;
                    break;
                }

                if (!string.IsNullOrEmpty(cmd))
                {
                    if (action == KeyEventActions.Down)
                    {
                        if (_down)
                        {
                            if (cmd.Equals(MusicService.CMDTOGGLEPAUSE) || cmd.Equals(MusicService.CMDPLAY))
                            {
                                if (_lastClickTime != 0 && eventTime - _lastClickTime > LONG_PRESS_DELAY)
                                {
                                    AcquireWakeLockAndSendMessage(context,
                                                                  _handler.ObtainMessage(MSG_LONGPRESS_TIMEOUT, context), 0);
                                }
                            }
                        }
                    }
                    else if (key.RepeatCount == 0)
                    {
                        if (keycode == Keycode.Headsethook)
                        {
                            if (eventTime - _lastClickTime > DOUBLE_CLICK)
                            {
                                _clickCounter = 0;
                            }

                            _clickCounter++;
                            _handler.RemoveMessages(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT);

                            var msg = _handler.ObtainMessage(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT, _clickCounter, 0,
                                                             context);

                            var delay = _clickCounter < 3 ? DOUBLE_CLICK : 0;

                            if (_clickCounter >= 3)
                            {
                                _clickCounter = 0;
                            }

                            _lastClickTime = eventTime;
                            AcquireWakeLockAndSendMessage(context, msg, delay);
                        }
                        else
                        {
                            StartTheService(context, cmd);
                        }

                        _launched = false;
                        _down     = true;
                    }
                }
                else
                {
                    _handler.RemoveMessages(MSG_LONGPRESS_TIMEOUT);
                    _down = false;
                }

                if (IsOrderedBroadcast)
                {
                    InvokeAbortBroadcast();
                }
                ReleaseWakeLockIfHandlerIdle();
            }
        }