protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);
			SetContentView (Resource.Layout.activity_imageandbutton);

			// Load the animation from resources
			_asteroidDrawable = (AnimationDrawable)Resources.GetDrawable (Resource.Drawable.spinning_asteroid);
			ImageView imageView = FindViewById<ImageView> (Resource.Id.imageView1);
			imageView.SetImageDrawable (_asteroidDrawable);

			Button spinAsteroidButton = FindViewById<Button> (Resource.Id.button1);
			spinAsteroidButton.Text = Resources.GetString (Resource.String.title_spinasteroid);
			spinAsteroidButton.Click += (sender, args) => _asteroidDrawable.Start ();
		}
				protected override void OnCreate (Bundle bundle)
				{
						base.OnCreate (bundle);
						SetContentView (Resource.Layout.Main);
						ImageView circle =  (ImageView) FindViewById<ImageView> (Resource.Id.circle);
						circleAnimation = (AnimationDrawable) circle.Drawable;
						circle.Touch += delegate(object sender, View.TouchEventArgs e) {
								if(e.Event.Action == MotionEventActions.Down){
									Console.WriteLine("Circle was pressed");
									circleAnimation.Stop();
									circle.SetImageResource(Resource.Drawable.circle);
								}
								if(e.Event.Action == MotionEventActions.Up){
									Console.WriteLine("Circle is not pressed");
									circle.SetImageDrawable(circleAnimation);
									circleAnimation.Run();
									//circleAnimation.Start();
								}
						};
						//SetContentView(new CircleView(this));
				}
 public RunnableAnonymousInnerClassHelper(Context outerInstance, AnimationDrawable animDrawable)
 {
     this.outerInstance = outerInstance;
 }
			public void SetUiEnable (bool enable)
			{
				if(remoteSettings.SendVehicleDataToMailbox){
					sliderLabel.Text = "Slider:";
				}
				else{
					sliderLabel.Text = "Motor:";
				}
				sensor1.Enabled = enable;
				sensor2.Enabled = enable;
				sensor3.Enabled = enable;
				sensor4.Enabled = enable;
				seekBar.Enabled = enable;
				circle.Enabled = enable;
				Android.Graphics.Color color = new Android.Graphics.Color (0x99, 0x99, 0x99);
				if (!enable) {
					circle.SetImageResource(Resource.Drawable.aniGray);
					circleAnimation.Stop();
				} 
				else 
				{
					color =	new Android.Graphics.Color (0xf2, 0x61, 0x00);
					circle.SetImageResource(Resource.Drawable.animation);
					circleAnimation = (AnimationDrawable) circle.Drawable;
					circleAnimation.Start();
					if(remoteSettings.SensorValueToSpeech){
						sensor1.Enabled = true;
						sensor2.Enabled = true;
						sensor3.Enabled = true;
						sensor4.Enabled = true;
					}
					else{
						sensor1.Enabled = false;
						sensor2.Enabled = false;
						sensor3.Enabled = false;
						sensor4.Enabled = false;
					}
				}
				angleText.SetTextColor(color);
				speedText.SetTextColor(color);
				sliderText.SetTextColor(color);
				angleLabel.SetTextColor(color);
				speedLabel.SetTextColor(color);
				sliderLabel.SetTextColor(color);
			}
			public override void OnActivityCreated (Bundle savedInstanceState)
			{
				base.OnActivityCreated (savedInstanceState);
				queue =  new QueueThread(OnDequeue);
				brickController = BrickController.Instance;
				remoteSettings = RemoteSettings.Instance;
				circle =  (ImageView) this.View.FindViewById<ImageView> (Resource.Id.circle);
				circleAnimation = (AnimationDrawable) circle.Drawable;
				//grayCircle = Resources.GetDrawable(Resource.Drawable.aniGray);
				seekBar = (SeekBar)this.View.FindViewById<SeekBar> (Resource.Id.seekBar);
				seekBar.Max = 200;
				
				angleLabel = (TextView)this.View.FindViewById<TextView> (Resource.Id.angleLabel);
				speedLabel = (TextView)this.View.FindViewById<TextView> (Resource.Id.speedLabel);
				sliderLabel = (TextView)this.View.FindViewById<TextView> (Resource.Id.seekLabel);
				
				angleText = (TextView)this.View.FindViewById<TextView> (Resource.Id.angleTextView);
				speedText = (TextView)this.View.FindViewById<TextView> (Resource.Id.speedTextView);
				sliderText = (TextView)this.View.FindViewById<TextView> (Resource.Id.seekTextView);
				
				
				sensor1 = (Button)this.View.FindViewById<Button> (Resource.Id.sensor1Button);
				sensor2 = (Button)this.View.FindViewById<Button> (Resource.Id.sensor2Button);
				sensor3 = (Button)this.View.FindViewById<Button> (Resource.Id.sensor3Button);
				sensor4 = (Button)this.View.FindViewById<Button> (Resource.Id.sensor4Button);
				
				sensor1.Click += delegate {
					queue.AddToQueue(
						delegate {
							string s = brickController.NXT.Sensor1.ReadAsString();
							Activity.RunOnUiThread(delegate() {
								//this should not run in the gui thread
								if(remoteSettings.SensorValueToSpeech && TabActivity.Speech != null){
									TabActivity.Speech.Speak(s, Android.Speech.Tts.QueueMode.Flush, null);
								}
							});
						},
						true,1 
					);
				};
				
				sensor2.Click += delegate {
					queue.AddToQueue(
						delegate {
							string s = brickController.NXT.Sensor2.ReadAsString();
							Activity.RunOnUiThread(delegate() {
								//this should not run in the gui thread
								if(remoteSettings.SensorValueToSpeech && TabActivity.Speech != null){
									TabActivity.Speech.Speak(s, Android.Speech.Tts.QueueMode.Flush, null);
								}
							});
						},
						true,1
					);
				};
				
				sensor3.Click += delegate {
					queue.AddToQueue(
						delegate {
							string s = brickController.NXT.Sensor3.ReadAsString();
							Activity.RunOnUiThread(delegate() {
								//this should not run in the gui thread
								if(remoteSettings.SensorValueToSpeech && TabActivity.Speech != null){
									TabActivity.Speech.Speak(s, Android.Speech.Tts.QueueMode.Flush, null);
								}
							});
						},
						true,1
					);
				};
				
				sensor4.Click += delegate {
					queue.AddToQueue(
						delegate {
							string s = brickController.NXT.Sensor4.ReadAsString();
							Activity.RunOnUiThread(delegate() {
								//this should not run in the gui thread
								if(remoteSettings.SensorValueToSpeech && TabActivity.Speech != null){
									TabActivity.Speech.Speak(s, Android.Speech.Tts.QueueMode.Flush, null);
								}
							});
						},
						true,1
					);
				};
				
				seekBar.Progress = 100;
				sliderText.Text = progress.ToString();
				
				seekBar.StopTrackingTouch += delegate(object sender, SeekBar.StopTrackingTouchEventArgs e) {
					e.SeekBar.Progress = 100;
					progress = 0;
					Activity.RunOnUiThread (delegate() {
						sliderText.Text = progress.ToString();
					});
					if(remoteSettings.SendVehicleDataToMailbox){
							queue.AddToQueue(
								delegate {
									SendDataToMailbox();
								},
								true,2
							);
					}
					else{
						queue.AddToQueue(
								delegate {
									additionalMotor.Off();
								},
								true,2
							);
					}	
				};
				seekBar.ProgressChanged += delegate(object sender, SeekBar.ProgressChangedEventArgs e) {
					progress = e.Progress - 100;
					Activity.RunOnUiThread (delegate() {
						sliderText.Text = progress.ToString();
					});
					if(remoteSettings.SendVehicleDataToMailbox){
							queue.AddToQueue(
								delegate {
									SendDataToMailbox();
								},
								true,2
							);
					}
					else{
						queue.AddToQueue(
								delegate {
									additionalMotor.On((sbyte) (e.Progress -100));
								},
								true,2
							);
					}	

				};
				circle.Touch += delegate(object sender, View.TouchEventArgs e) {
					if(e.Event.Action == MotionEventActions.Up){
						angleText.Text = "0.0";
						speedText.Text = "0.0";
						angle = 0.0f;
						speed = 0.0f;
						wasRunningForward = true;
						if(remoteSettings.SendVehicleDataToMailbox){
							queue.AddToQueue(
								delegate {
									SendDataToMailbox();
								},
								true,2
							);
						}
						else{
							queue.AddToQueue(
								delegate {
									brickController.NXT.Vehicle.Off();
								},
								true,3
							);
						
						
						}
						circle.SetImageResource(Resource.Drawable.animation);
						circleAnimation = (AnimationDrawable) circle.Drawable;
						circleAnimation.Start();
					}
					if(e.Event.Action == MotionEventActions.Move || e.Event.Action == MotionEventActions.Down) {
						//movingOnCircle = true;
						if(diameter == 0){
							diameter = circle.Width / 2;
						}
						x = e.Event.GetX()-diameter;
						y = -(e.Event.GetY()-diameter);
						float outside = diameter*(float)1.06;
						if( !(x > outside || x < -outside || y > outside || y < -outside) ){
							if(x > 0.0){
								angle = Math.Atan(y/x);
								if( y < 0.0)
									angle = Math.Atan(y/x)+ 2*Math.PI;
							}
							else{
								angle = Math.Atan(y/x) + Math.PI;
							}
							angle = angle + remoteSettings.DegreeOffset;
							//convert radians to degree
							angle = (angle * (180.0 / Math.PI))%360;
							speed = (float)Math.Sqrt( x*x + y*y);
							speed = speed/diameter * 100;  
							if(speed > 100.0){
								speed = (float)100.0;
							}
						}
						else{
							speed = 0.0f;
							angle = 0.0f;
						}
						
						int intSpeed =(int) speed;
						Activity.RunOnUiThread (delegate() {
						
							if(intSpeed < 10){
								circle.SetImageResource(Resource.Drawable.ani0);
							}
							else if(intSpeed < 20){
								circle.SetImageResource(Resource.Drawable.ani1);
							
							}
							else if(intSpeed < 30){
								circle.SetImageResource(Resource.Drawable.ani2);
							
							}
							else if(intSpeed < 40){
								circle.SetImageResource(Resource.Drawable.ani3);
							
							}
							else if(intSpeed < 50){
								circle.SetImageResource(Resource.Drawable.ani4);
							
							}
							else if(intSpeed < 60){
								circle.SetImageResource(Resource.Drawable.ani5);
							
							}
							else if(intSpeed < 70){
								circle.SetImageResource(Resource.Drawable.ani6);
							
							}
							else if(intSpeed < 80){
							
								circle.SetImageResource(Resource.Drawable.ani7);
							}
							else if(intSpeed < 90){
								circle.SetImageResource(Resource.Drawable.ani8);
							
							}
							else{
								circle.SetImageResource(Resource.Drawable.ani9);
							
							}
							circleAnimation.Stop();
							//angleText.Text = "Angle: " + string.Format("{0,5:###.0}", angle).PadLeft(7);
							//speedText.Text = "Speed: " + string.Format("{0,5:###.0}", speed).PadLeft(7);
							angleText.Text = string.Format("{0,5:###.0}", angle);
							speedText.Text = string.Format("{0,5:###.0}", speed);

						});
						if(remoteSettings.SendVehicleDataToMailbox){
							queue.AddToQueue(
								delegate {
									SendDataToMailbox();
								},
								true,2
							);
						}
						else{
							queue.AddToQueue(
								delegate {
									if(angle >= 10.0f && angle < 80.0f){
										brickController.NXT.Vehicle.TurnLeftForward((sbyte)speed, (sbyte)(100.0f-(angle-10.0f)/70.0f * 100.0f));
										wasRunningForward = true;
										return;
									}
									if(angle >= 100.0f && angle < 170.0f){
										brickController.NXT.Vehicle.TurnLeftReverse((sbyte)speed, (sbyte)(100.0f-(170-(angle-10.0f))/70.0f * 100.0f));
										wasRunningForward = false;
										return;
									}
									if(angle >= 190.0f && angle < 260.0f){
										brickController.NXT.Vehicle.TurnRightReverse((sbyte)speed, (sbyte)(100.0f-((angle-10.0f)-190)/70.0f * 100.0f));
										wasRunningForward = false;
										return;
									}
									if(angle >= 280.0f && angle <= 350.0f){
										brickController.NXT.Vehicle.TurnRightForward((sbyte)speed, (sbyte)(100.0f-(350-(angle-10.0f))/70.0f * 100.0f));
										wasRunningForward = true;
										return;
									}
									if( (angle < 10.0f && angle >= 0.0f) || (angle > 350.0f) ){
										brickController.NXT.Vehicle.Forward((sbyte)speed);
										return;
									}
									if( angle >= 170.0f && angle < 190.0f){
										brickController.NXT.Vehicle.Backward((sbyte)speed);
										return;
									}
									if( angle >= 80.0f && angle < 100.0f){
										if(wasRunningForward){
											brickController.NXT.Vehicle.SpinLeft((sbyte)speed);
										}
										else{
											brickController.NXT.Vehicle.SpinRight((sbyte)speed);
										}
										return;
									}
									if( angle >= 260.0f && angle < 280.0f){
										if(wasRunningForward){
											brickController.NXT.Vehicle.SpinRight((sbyte)speed);
										}
										else{
											brickController.NXT.Vehicle.SpinLeft((sbyte)speed);
										}
										return;
									}
								},
								true,3
							);
						}
					}
				};
				circleAnimation.Start();
			}
Example #6
0
		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);

			#if DEBUG
			Xamarin.Insights.Initialize("ef02f98fd6fb47ce8624862ab7625b933b6fb21d", this);
			#else
			Xamarin.Insights.Initialize ("8da86f8b3300aa58f3dc9bbef455d0427bb29086", this);
			#endif

			mapView = FindViewById<MapView> (Resource.Id.map);
			mapView.OnCreate (bundle);

			mapView.Visibility = ViewStates.Invisible;
			viewModel = new CoffeeFilterViewModel ();
			ServiceContainer.Register<CoffeeFilterViewModel> (viewModel);
			adapter = new PlacesPagerAdapter (SupportFragmentManager, viewModel);
			pager = FindViewById<ViewPager> (Resource.Id.pager);
			pager.Adapter = adapter;
			progressBar = FindViewById<ImageView> (Resource.Id.progressBar);
			errorImage = FindViewById<ImageView> (Resource.Id.error);
			coffeeProgress = (AnimationDrawable)progressBar.Background;
			progressBar.Visibility = ViewStates.Gone;

			pager.PageSelected += (sender, e) => UpdateMap (e.Position);
			pager.PageScrollStateChanged += (sender, e) => {
				if (e.State == (int)ScrollState.TouchScroll)
					refresher.Enabled = false;
				else
					refresher.Enabled = true;
			};

			refresher = FindViewById<SwipeRefreshLayout> (Resource.Id.refresher);
			refresher.SetColorSchemeColors (Resource.Color.accent);
			refresher.Refresh += (sender, args) => {
				RefreshData (true);
				refresher.PostDelayed (() => {
					refresher.Refreshing = false;
				}, 250);
			};

			SupportActionBar.SetDisplayHomeAsUpEnabled (false);
			SupportActionBar.SetHomeButtonEnabled (false);
			mapView.GetMapAsync (this);
			CheckGooglePlayServices ();

			// No savedInstanceState, so it is the first launch of this activity
			if (bundle == null && AppInviteReferral.HasReferral(Intent)) {
				// In this case the referral data is in the intent launching the MainActivity,
				// which means this user already had the app installed. We do not have to
				// register the Broadcast Receiver to listen for Play Store Install information
				LaunchDeepLinkActivity(Intent);

			}
		}