예제 #1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            AppCenter.Start("ff65fe46-1505-497b-95b7-001ce1e74a6a", typeof(Analytics), typeof(Crashes));

            myReceiver = new LocastionReceiver {
                Context = this
            };

            if (CheckPermissions())
            {
                ServiceConnection = new CustomServiceConnection {
                    Activity = this
                }
            }
            ;

            // Check that the user hasn't revoked permissions by going to Settings.
            //     if (Utils.RequestingLocationUpdates(this))
            {
                if (!CheckPermissions())
                {
                    RequestPermissions();
                }
            }
        }
예제 #2
0
        public override void OnRequestPermissionsResult(int requestCode, string[] permissions,
                                                        Android.Content.PM.Permission[] grantResults)
        {
            Log.Info(Tag, "onRequestPermissionResult");
            if (requestCode == RequestPermissionsRequestCode)
            {
                if (grantResults.Length <= 0)
                {
                    // If user interaction was interrupted, the permission request is cancelled and you
                    // receive empty arrays.
                    Log.Info(Tag, "User interaction was cancelled.");
                }
                else if (grantResults[0] == PermissionChecker.PermissionGranted)
                {
                    // Permission was granted.

                    if (ServiceConnection == null)
                    {
                        ServiceConnection = new CustomServiceConnection {
                            Activity = this
                        };
                        BindService(new Intent(this, typeof(LocationUpdatesService)), ServiceConnection, Bind.AutoCreate);
                    }
                    //    Service.RequestLocationUpdates();
                }
                else
                {
                    // Permission denied.
                    //   SetButtonsState(false);
                    Snackbar.Make(
                        FindViewById(Resource.Id.activity_main),
                        Resource.String.permission_denied_explanation,
                        Snackbar.LengthIndefinite)
                    .SetActionTextColor(Color.White)
                    .SetAction(Resource.String.settings, (obj) =>
                    {
                        // Build intent that displays the App settings screen.
                        Intent intent = new Intent();
                        intent.SetAction(Android.Provider.Settings.ActionApplicationDetailsSettings);
                        var uri = Uri.FromParts("package", PackageName, null);
                        intent.SetData(uri);
                        intent.SetFlags(ActivityFlags.NewTask);
                        StartActivity(intent);
                    })
                    .Show();
                }
            }
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            myReceiver = new MyReceiver {
                Context = this
            };
            ServiceConnection = new CustomServiceConnection {
                Activity = this
            };

            SetContentView(Resource.Layout.activity_main);

            // Check that the user hasn't revoked permissions by going to Settings.
            if (Utils.RequestingLocationUpdates(this))
            {
                if (!CheckPermissions())
                {
                    RequestPermissions();
                }
            }
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            //initialize media player
            mediaPlayerConnection = new CustomServiceConnection(this);
            DoBindService();

            SetContentView(Resource.Layout.activity_exhibit_details);

            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
            {
                Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
            }

            var toolbar = (Toolbar)FindViewById(Resource.Id.toolbar);

            toolbar.SetNavigationIcon(Resource.Drawable.ic_clear_white_24dp);
            SetSupportActionBar(toolbar);
            audioSeekbar = FindViewById <SeekBar> (Resource.Id.audio_progress_bar);
            audioSeekbar.ProgressChanged += (sender, args) => {
                if (mediaPlayerService != null && args.FromUser)
                {
                    mediaPlayerService.SeekTo(args.Progress);
                }
            };

            SupportActionBar.SetDisplayHomeAsUpEnabled(true);

            sharedPreferences = PreferenceManager.GetDefaultSharedPreferences(this);

            if (savedInstanceState != null)
            {
                // activity re-creation because of device rotation, instant run, ...
                exhibitId        = savedInstanceState.GetString(KEY_EXHIBIT_ID);
                exhibit          = ExhibitManager.GetExhibit(exhibitId);
                currentPageIndex = savedInstanceState.GetInt(KEY_CURRENT_PAGE_INDEX, 0);
                isAudioPlaying   = savedInstanceState.GetBoolean(KEY_AUDIO_PLAYING, false);
                if (!isAudioPlaying)
                {
                    pauseAudioPlaybackFlag = true;
                }
                isAudioToolbarHidden = savedInstanceState.GetBoolean(KEY_AUDIO_TOOLBAR_HIDDEN, true);
                if (!isAudioToolbarHidden)
                {
                    showAudioToolbarFlag = true;
                }
                extras         = savedInstanceState.GetBundle(KEY_EXTRAS);
                isCaptionShown = savedInstanceState.GetBoolean(KEY_CAPTION_SHOWN);

                var selectedTab   = savedInstanceState.GetInt(KEY_CURRENT_CAPTION_TAB);
                var currentSource = savedInstanceState.GetInt(KEY_CURRENT_SOURCE);

                if (isCaptionShown)
                {
                    ShowCaptions(selectedTab, currentSource);
                }

                isHelpDialogShown = savedInstanceState.GetBoolean(KEY__HELP_DIALOG_SHOWN, false);
                isSwitchToNextPageAutomatically = savedInstanceState.GetBoolean(KEY_PAGE_SWITCH_BASED_ON_SETTINGS, false);
            }
            else
            {
                // activity creation because of intent
                var intent = Intent;
                extras    = intent.Extras;
                exhibitId = intent.GetStringExtra(INTENT_EXTRA_EXHIBIT_ID);
                exhibit   = ExhibitManager.GetExhibit(exhibitId);
            }
            Title = exhibit.Name;

            if (exhibit.Pages.Count == 0)
            {
                throw new NullPointerException("Cannot display exhibit with no pages.");
            }

            // set up bottom sheet behavior
            bottomSheet         = FindViewById(Resource.Id.bottom_sheet);
            bottomSheetBehavior = BottomSheetBehavior.From(bottomSheet);
            bottomSheetBehavior.SetBottomSheetCallback(new CustomBottomSheetCallback(this));

            // audio toolbar
            revealView            = (LinearLayout)FindViewById(Resource.Id.reveal_items);
            revealView.Visibility = ViewStates.Invisible;

            // Does not work with animations:
            // see also: http://stackoverflow.com/questions/7289827/how-to-start-animation-immediately-after-oncreate

            // set up play / pause toggle
            btnPlayPause        = (ImageButton)FindViewById(Resource.Id.btnPlayPause);
            btnPlayPause.Click += (sender, args) => {
                if (isAudioPlaying)
                {
                    PauseAudioPlayback();
                    isAudioPlaying = false;
                }
                else
                {
                    StartAudioPlayback();
                    isAudioPlaying = true;
                    btnPlayPause.SetImageResource(Android.Resource.Color.Transparent);
                }
                UpdatePlayPauseButtonIcon();
            };

            // set up CC button
            var btnCaptions = (ImageButton)FindViewById(Resource.Id.btnCaptions);

            btnCaptions.Click += (sender, args) => { ShowCaptions(); };

            // set up previous / next button
            btnPreviousPage        = (ImageButton)FindViewById(Resource.Id.buttonPrevious);
            btnPreviousPage.Click += (sender, args) => { DisplayPreviousExhibitPage(); };

            btnNextPage        = (ImageButton)FindViewById(Resource.Id.buttonNext);
            btnNextPage.Click += (sender, args) => { DisplayNextExhibitPage(); };

            fab        = (FloatingActionButton)FindViewById(Resource.Id.fab);
            fab.Click += (sender, args) => {
                switch (fabAction)
                {
                case BottomSheetConfig.FabAction.Next:
                    DisplayNextExhibitPage();
                    break;

                case BottomSheetConfig.FabAction.Collapse:
                    SetFabAction(BottomSheetConfig.FabAction.Expand);
                    break;

                case BottomSheetConfig.FabAction.Expand:
                    SetFabAction(BottomSheetConfig.FabAction.Collapse);
                    break;

                default:
                    throw new IllegalArgumentException("Unsupported FAB action!");
                }
            };
        }