Esempio n. 1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.CreateChooseLocationActivity);

            string chosenData = Intent.GetStringExtra("CHOSEN") ?? "";

            previouslyChosen = !string.IsNullOrWhiteSpace(chosenData) ?
                               JsonConvert.DeserializeObject <List <Place> >(chosenData) :
                               new List <Place>();

            dialog = new ProgressDialog(this);
            dialog.SetMessage(Resources.GetString(Resource.String.Connecting));
            dialog.Show();

            string targetData = Intent.GetStringExtra("TARGET") ?? "";

            if (!string.IsNullOrWhiteSpace(targetData))
            {
                targetLoc = JsonConvert.DeserializeObject <Map_Location>(targetData);
                LoadData();
            }
            else
            {
                if (AndroidUtils.IsGooglePlayServicesInstalled(this) && googleApiClient == null)
                {
                    googleApiClient = new GoogleApiClient.Builder(this)
                                      .AddConnectionCallbacks(this)
                                      .AddOnConnectionFailedListener(this)
                                      .AddApi(LocationServices.API)
                                      .Build();
                }
            }
        }
Esempio n. 2
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.CameraActivity);

            string jsonData = Intent.GetStringExtra("JSON") ?? "";

            learningTask = JsonConvert.DeserializeObject <AppTask>(jsonData, new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Auto
            });
            activityId = Intent.GetIntExtra("ACTID", -1);

            if (bundle == null)
            {
                if (learningTask.TaskType.IdName == "TAKE_VIDEO")
                {
                    RequestedOrientation = ScreenOrientation.Landscape;
                    if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
                    {
                        FragmentManager.BeginTransaction().Replace(Resource.Id.container, Camera2VideoFragment.NewInstance()).Commit();
                    }
                    else
                    {
                        FragmentManager.BeginTransaction().Replace(Resource.Id.container, Camera1VideoFragment.NewInstance()).Commit();
                    }
                }
                else
                {
                    if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
                    {
                        FragmentManager.BeginTransaction().Replace(Resource.Id.container, Camera2Fragment.NewInstance()).Commit();
                    }
                    else
                    {
                        FragmentManager.BeginTransaction().Replace(Resource.Id.container, Camera1Fragment.NewInstance()).Commit();
                    }
                }
            }

            if (!AndroidUtils.IsGooglePlayServicesInstalled(this) || googleApiClient != null)
            {
                return;
            }

            googleApiClient = new GoogleApiClient.Builder(this)
                              .AddConnectionCallbacks(this)
                              .AddOnConnectionFailedListener(this)
                              .AddApi(LocationServices.API)
                              .Build();

            locRequest = new LocationRequest();
        }
        public override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Load from cached data from the database if available,
            // just in case we can't contact the server
            List <FeedSection> cached = await((MainActivity)Activity).GetCachedContent(false);

            // Check for recently opened activities
            FeedSection recents = await LoadRecent();

            if (recents != null)
            {
                cached.Insert(0, recents);
            }

            var metrics   = Resources.DisplayMetrics;
            var widthInDp = AndroidUtils.ConvertPixelsToDp(metrics.WidthPixels, Activity);

            int cols = Math.Max(widthInDp / 300, 1);

            adapter            = new FeedItemsAdapter(cached, await AndroidUtils.GetDbManager().ConfigureAwait(false));
            adapter.ItemClick += OnItemClick;

            if (savedInstanceState != null)
            {
                adapter.Data = JsonConvert.DeserializeObject <List <FeedSection> >(savedInstanceState.GetString("MAIN_ADAPTER_DATA"));
                adapter.NotifyDataSetChanged();
            }

            layoutManager = new GridLayoutManager(Activity, cols);
            layoutManager.SetSpanSizeLookup(new GridSpanner(adapter, cols));

            if (!AndroidUtils.IsGooglePlayServicesInstalled(Activity) || googleApiClient != null)
            {
                return;
            }

            googleApiClient = new GoogleApiClient.Builder(Activity)
                              .AddConnectionCallbacks(this)
                              .AddOnConnectionFailedListener(this)
                              .AddApi(LocationServices.API)
                              .Build();
            googleApiClient?.Connect();
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.LocationHunActivity);

            string thisJsonData = Intent.GetStringExtra("JSON") ?? "";

            learningTask = JsonConvert.DeserializeObject <LearningTask>(thisJsonData,
                                                                        new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Auto
            });

            if (learningTask == null)
            {
                learningTask = new LearningTask()
                {
                    Description = Intent.GetStringExtra("Description"),
                };
                target = JsonConvert.DeserializeObject <LocationHuntLocation>(Intent.GetStringExtra("Target"));
            }
            else
            {
                target = JsonConvert.DeserializeObject <LocationHuntLocation>(learningTask.JsonData);
            }

            SupportActionBar.Title = learningTask.Description;

            TextView taskDesc = FindViewById <TextView>(Resource.Id.taskDesc);

            taskDesc.Text = learningTask.Description;

            distanceText      = FindViewById <TextView>(Resource.Id.distanceText);
            distanceText.Text = "Please wait";

            Color.Rgb(
                Color.GetRedComponent(distanceText.CurrentTextColor),
                Color.GetGreenComponent(distanceText.CurrentTextColor),
                Color.GetBlueComponent(distanceText.CurrentTextColor));

            accuracyText      = FindViewById <TextView>(Resource.Id.accuracyText);
            accuracyText.Text = "Connecting";

            image       = FindViewById <ImageView>(Resource.Id.taskImage);
            image.Alpha = LowAlpha;

            Button openMapButton = FindViewById <Button>(Resource.Id.openMapButton);

            openMapButton.Click     += OpenMapButton_Click;
            openMapButton.Visibility = (target.MapAvailable == null || target.MapAvailable == true)
                ? ViewStates.Visible : ViewStates.Gone;

            if (!AndroidUtils.IsGooglePlayServicesInstalled(this) || googleApiClient != null)
            {
                return;
            }

            googleApiClient = new GoogleApiClient.Builder(this)
                              .AddConnectionCallbacks(this)
                              .AddOnConnectionFailedListener(this)
                              .AddApi(LocationServices.API)
                              .Build();
            locRequest = new LocationRequest();
        }