void Awake() { _controller = GetComponent<CharacterController2D>(); _animator = GetComponent<Animator>(); _respawner = GetComponent<FallDeath>(); _flashlight = GetComponentInChildren<Flashlight>(); }
// Use this for initialization void Start() { playerHealth = GetComponent<PlayerStats>(); flashlighObject = transform.FindChild("FirstPersonCamera").FindChild("Flashlight"); if (flashlighObject != null) flashlight = flashlighObject.GetComponent<Flashlight>(); }
void Awake() { movement = GetComponent<PlayerMovement>(); //Extract the player index from the name of player if (this.name == "Player1") currentIndex = XInputDotNetPure.PlayerIndex.One; else if (this.name == "Player2") currentIndex = XInputDotNetPure.PlayerIndex.Two; flashlight = GetComponent<Flashlight>(); flashlight.currentIndex = currentIndex; }
// Use this for initialization void Start () { anim = GetComponent<Animator> (); fLight = fLight.GetComponent<Flashlight> (); manager = manager.GetComponent<GameManager> (); rotationVector = fLight.transform.rotation.eulerAngles; rotationVector.y = 77.5f; //Playing AudioSources sources = new AudioSource[clips.Length]; int i = 0; while (i < clips.Length) { GameObject child = new GameObject ("Player"); child.transform.parent = gameObject.transform; sources[i] = child.AddComponent("AudioSource") as AudioSource; sources[i].clip = clips[i]; i++; } }
//Hello morse private async void HelloBtn_Clicked(object sender, EventArgs e) { try { await Flashlight.TurnOnAsync(); await Flashlight.TurnOffAsync(); await Flashlight.TurnOnAsync(); await Flashlight.TurnOffAsync(); await Flashlight.TurnOnAsync(); await Flashlight.TurnOffAsync(); await Flashlight.TurnOnAsync(); await Flashlight.TurnOffAsync(); await Task.Delay(650); await Flashlight.TurnOnAsync(); await Flashlight.TurnOffAsync(); await Task.Delay(650); await Flashlight.TurnOnAsync(); await Flashlight.TurnOffAsync(); await Flashlight.TurnOnAsync(); await Task.Delay(700); await Flashlight.TurnOffAsync(); await Flashlight.TurnOnAsync(); await Flashlight.TurnOffAsync(); await Flashlight.TurnOnAsync(); await Flashlight.TurnOffAsync(); await Task.Delay(650); await Flashlight.TurnOnAsync(); await Flashlight.TurnOffAsync(); await Flashlight.TurnOnAsync(); await Task.Delay(700); await Flashlight.TurnOffAsync(); await Flashlight.TurnOnAsync(); await Flashlight.TurnOffAsync(); await Flashlight.TurnOnAsync(); await Flashlight.TurnOffAsync(); await Task.Delay(650); await Flashlight.TurnOnAsync(); await Task.Delay(700); await Flashlight.TurnOffAsync(); await Flashlight.TurnOnAsync(); await Task.Delay(700); await Flashlight.TurnOffAsync(); await Flashlight.TurnOnAsync(); await Task.Delay(700); await Flashlight.TurnOffAsync(); } catch (FeatureNotSupportedException fnsEx) { //Handle not supported on device exception } catch (PermissionException pEx) { //Handle permission exception } catch (Exception ex) { //Unable to turn on/off flashlight } }
public abstract void OnExit(Flashlight flashlight);
/// <summary> /// Initialize the default values. /// </summary> protected override void OnEnable() { base.OnEnable(); m_Flashlight = target as Flashlight; }
public override void HandleMode(Flashlight contextFlashlight) { }
// Use this for initialization void Start () { _light = GameObject.FindGameObjectWithTag ("Flashlight").GetComponent<Flashlight>(); }
public override IFlashlight Flashlight() { IFlashlight flashlight = new Flashlight(); return(flashlight); }
protected override async void OnResume() { await Flashlight.TurnOnAsync(); }
public override void OnEnter(Flashlight flashlight) { }
public override void OnExit(Flashlight flashlight) { }
private void btnFlashlightOn_Click(object sender, EventArgs e) { if (!Flashlight.GetIsOn() && Flashlight.GetBulbState() && Flashlight.GetBatteriesInCount() >= 2 && Flashlight.IsEnoughPower()) { for (int i = 0; i < Flashlight.GetBatteriesInCount(); i++) { Flashlight.ConsumePowerFromBatteriesIn(i); switch (i + 1) { case 1: tbBattery1State.Text = Flashlight.GetPowerFromBatteriesIn(i).ToString(); prgBattery1.Value = Flashlight.GetPowerFromBatteriesIn(i); break; case 2: tbBattery2State.Text = Flashlight.GetPowerFromBatteriesIn(i).ToString(); prgBattery2.Value = Flashlight.GetPowerFromBatteriesIn(i); break; case 3: tbBattery3State.Text = Flashlight.GetPowerFromBatteriesIn(i).ToString(); prgBattery3.Value = Flashlight.GetPowerFromBatteriesIn(i); break; case 4: tbBattery4State.Text = Flashlight.GetPowerFromBatteriesIn(i).ToString(); prgBattery4.Value = Flashlight.GetPowerFromBatteriesIn(i); break; } } tbFlashlightState.Text = "WŁĄCZONA"; tbFlashlightState.BackColor = Color.Green; Flashlight.Turn(true); } else { if (Flashlight.GetIsOn()) { MessageBox.Show("Latarka jest już włączona!", "Błąd!"); } else if (!Flashlight.GetBulbState() && Flashlight.GetBatteriesInCount() < 2) { MessageBox.Show("W latarce nie ma żarówki ani dostatecznej ilości baterii.", "Błąd!"); } else if (!Flashlight.GetBulbState() && !Flashlight.IsEnoughPower()) { MessageBox.Show("W latarce nie ma żarówki ani dostatecznej ilości mocy w bateriach.", "Błąd!"); } else if (!Flashlight.GetBulbState()) { MessageBox.Show("W latarce nie ma żarówki!", "Błąd!"); } else if (Flashlight.GetBatteriesInCount() < 2) { MessageBox.Show("W latarce nie ma dostatecznej ilości baterii.", "Błąd!"); } else { MessageBox.Show("W latarce nie ma dostatecznej ilości mocy.", "Błąd!"); } } }
/// <summary> /// Scan request was made from Web (through Link or AppLink). /// </summary> /// <param name="url">Who called this function</param> /// <remarks> /// The app can be started with a SCAN-call through the webpage: "http://SCAN/". This will work only if the link is opened in this app.<br></br> /// You can also open the scanner with "qr2web://scan/". This will open this app even if you are using your default webbrowser. /// </remarks> static public void StartScanFromWeb(string url) { string urlWithoutProtocol; // Check Mocha protocols if (url.StartsWith("mochabarcode:")) { urlWithoutProtocol = url.Substring("mochabarcode:".Length).TrimStart('/'); if (urlWithoutProtocol.StartsWith("CONFIG", StringComparison.CurrentCultureIgnoreCase)) { //mochabarcode://CONFIG=http://mochasoft.com/test1.htm&autolock=1&function=1&field=1& //history = 1 & scan = 1 & back = 1 & forward = 1 & reload = 1 & reloadstart = 1 & shake = 0 //& ignorefirst = 0 & ignorelast = 0 & beep = 1 string[] sParams = urlWithoutProtocol.Remove(' ').Split('&'); foreach (string sParam in sParams) { if (sParam.IndexOf('=') > 0) { string value = (sParam.Split('='))[1].ToLower(); switch ((sParam.Split('='))[0].ToLower()) { case "CONFIG": if (value.Length > 5) { Parameters.Options.HomePage = value; } break; case "history": if (value == "1") { Parameters.Options.SaveHistory = true; } else { Parameters.Options.SaveHistory = false; } break; } } } } else if (urlWithoutProtocol.StartsWith("CALLBACK=", StringComparison.CurrentCultureIgnoreCase)) { Parameters.TemporaryOptions.SetLookup("", urlWithoutProtocol.Substring("CALLBACK=".Length), Parameters.EmulationTypes.MOCHASOFT); Instance.StartScan(); } else { Parameters.TemporaryOptions.SetLookup("", "", Parameters.EmulationTypes.MOCHASOFT); Instance.StartScan(); } } // check pic 2 shop pro protocol else if (url.StartsWith("p2spro")) { urlWithoutProtocol = url.Substring("p2spro:".Length).TrimStart('/'); if (urlWithoutProtocol.StartsWith("configure?", StringComparison.CurrentCultureIgnoreCase) || urlWithoutProtocol.StartsWith("configure/?", StringComparison.CurrentCultureIgnoreCase)) { //p2spro://configure?lookup=LOOKUP_URL&home=HOME_URL&formats=EAN13,EAN8,UPCE,ITF,CODE39,CODE128,CODE93,STD2OF5,CODABAR,QR &gps=True|False //&hidebuttons = True | False //& autorotate = True | False //& highres = True | False //& settings = True | False string[] sParams = urlWithoutProtocol.Substring( (urlWithoutProtocol.StartsWith("configure?", StringComparison.CurrentCultureIgnoreCase) ? "configure?".Length : "configure/?".Length) ).Remove(' ').Split('&'); foreach (string sParam in sParams) { if (sParam.IndexOf('=') > 0) { string value = (sParam.Split('='))[1].ToLower(); switch ((sParam.Split('='))[0].ToLower()) { case "home": if (value.Length > 5) { Parameters.Options.HomePage = value; } break; case "autorotate": if (value.ToLower() == "true") { Parameters.Options.LockPortrait = true; } else { Parameters.Options.LockPortrait = false; } break; case "formats": Parameters.Options.AcceptBarcode_Code = value.ToLower().Contains("code"); Parameters.Options.AcceptBarcode_Ean = value.ToLower().Contains("ean"); Parameters.Options.AcceptBarcode_Upc = value.ToLower().Contains("upc"); break; } } } } else if (urlWithoutProtocol.StartsWith("scan?", StringComparison.CurrentCultureIgnoreCase) || urlWithoutProtocol.StartsWith("scan/?", StringComparison.CurrentCultureIgnoreCase)) { if (urlWithoutProtocol.Contains("callback=")) { string callbackCommand = url.Substring(url.IndexOf("callback=", StringComparison.CurrentCultureIgnoreCase) + "callback=".Length); if (callbackCommand.IndexOf('&') > 0) { callbackCommand = callbackCommand.Substring(0, callbackCommand.IndexOf('&')); } if (callbackCommand.StartsWith("javascript:", StringComparison.CurrentCultureIgnoreCase)) { Parameters.TemporaryOptions.SetLookup(callbackCommand.Substring("javascript:".Length), "", Parameters.EmulationTypes.PIC2SHOP); } else { Parameters.TemporaryOptions.SetLookup("", callbackCommand, Parameters.EmulationTypes.PIC2SHOP); } } Instance.StartScan(); } else { Instance.StartScan(); } } // check qr to Web protocol else if (url.StartsWith("qr2web")) { urlWithoutProtocol = url.Substring("qr2web:".Length).TrimStart('/'); if (urlWithoutProtocol.ToLower().StartsWith("parameters")) { MainThread.BeginInvokeOnMainThread(() => { SaveNewParameters(urlWithoutProtocol.Substring("parameters".Length).TrimStart('/')); }); } else if (urlWithoutProtocol.ToLower().StartsWith("torch")) { var time = urlWithoutProtocol.ToLower().Split("/"); if (time.Length == 2 && time[1] != "off") { new Task(async() => { try { MainThread.BeginInvokeOnMainThread(async() => { await Flashlight.TurnOnAsync(); }); int timeout = 2000; int.TryParse(time[1], out timeout); if (timeout < 1000) { timeout = 1000; } else if (timeout > 30000) { timeout = 30000; } await Task.Delay(timeout); MainThread.BeginInvokeOnMainThread(async() => { await Flashlight.TurnOffAsync(); }); } catch (Exception ex) { Console.Write(ex); } }).Start(); } else { try { MainThread.BeginInvokeOnMainThread(async() => { await Flashlight.TurnOffAsync(); }); } catch (Exception ex) { Console.Write(ex); } } } else { Instance.StartScan(); } } // no protocol found, start the normal scan and return the result in the standard function else if (Instance != null) { Instance.StartScan(); } }
private void btnBulbIn_Click(object sender, EventArgs e) { Flashlight.PlugInBulb(); tbBulbStrength.Text = Bulb.GetStrength().ToString(); tbBulbStrength.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(230))))); }
private void btnFlashlightOff_Click(object sender, EventArgs e) { Flashlight.Turn(false); tbFlashlightState.Text = "WYŁĄCZONA"; tbFlashlightState.BackColor = Color.Red; }
// Use this for initialization void Start() { miloFlashLight = GameObject.Find("Flashlight").GetComponent <Flashlight>(); capsuleCollider = GetComponent <CapsuleCollider>(); }
public override void OnEnter(Flashlight context) { context.SetState(new SOLID()); }
public override void HandlePowerPressed(Flashlight flashlight) { flashlight.TurnLampOff(); flashlight.SetState(new Off()); }
public override void ModePressed(Flashlight context) { context.flashLEDs(); context.SetState(new SOLID()); }
public override void Tick() { if (CBody == null || Body == null) { return; } Body.ActivityInformation.Activate(); if (ServerFlags.HasFlag(YourStatusFlags.NO_ROTATE)) { tyaw = MouseHandler.MouseDelta.X; tpitch = MouseHandler.MouseDelta.Y; tyaw += GamePadHandler.TotalDirectionX * 90f * TheRegion.Delta; tpitch += GamePadHandler.TotalDirectionY * 45f * TheRegion.Delta; } else { Direction.Yaw += MouseHandler.MouseDelta.X; Direction.Pitch += MouseHandler.MouseDelta.Y; Direction.Yaw += GamePadHandler.TotalDirectionX * 90f * TheRegion.Delta; Direction.Pitch += GamePadHandler.TotalDirectionY * 45f * TheRegion.Delta; } Vector2 tmove; if (Math.Abs(GamePadHandler.TotalMovementX) > 0.05) // TODO: Threshold CVar! { tmove.X = (float)GamePadHandler.TotalMovementX; } else { tmove.X = 0; } if (Math.Abs(GamePadHandler.TotalMovementY) > 0.05) { tmove.Y = (float)GamePadHandler.TotalMovementY; } else { tmove.Y = 0; } if (tmove.LengthSquared() > 1) { tmove.Normalize(); } if (tmove.X == 0 && tmove.Y == 0) { if (Forward) { tmove.Y = 1; } if (Backward) { tmove.Y = -1; } if (Rightward) { tmove.X = 1; } if (Leftward) { tmove.X = -1; } if (tmove.LengthSquared() > 1) { tmove.Normalize(); } } XMove = (float)tmove.X; YMove = (float)tmove.Y; if (GamePadHandler.JumpKey) { PGPJump = true; Upward = true; } else if (PGPJump) { Upward = false; PGPJump = false; } if (GamePadHandler.PrimaryKey) { PGPPrimary = true; Click = true; } else if (PGPPrimary) { Click = false; PGPPrimary = false; } if (GamePadHandler.SecondaryKey) { PGPSecondary = true; AltClick = true; } else if (PGPSecondary) { AltClick = false; PGPSecondary = false; } if (GamePadHandler.ChangeLeft) { if (!PGPDPadLeft) // TODO: Holdable? { PGPDPadLeft = true; TheClient.Commands.ExecuteCommands("itemprev"); // TODO: Less lazy! } } else { PGPDPadLeft = false; } if (GamePadHandler.ChangeRight) { if (!PGPDPadRight) // TODO: Holdable? { PGPDPadRight = true; TheClient.Commands.ExecuteCommands("itemnext"); // TODO: Less lazy! } } else { PGPDPadRight = false; } if (GamePadHandler.UseKey) { PGPUse = true; Use = true; } else if (PGPUse) { PGPUse = false; Use = false; } if (GamePadHandler.ReloadKey) { PGPReload = true; TheClient.Commands.ExecuteCommands("weaponreload"); // TODO: Less lazy! } else if (PGPUse) { PGPReload = false; } if (GamePadHandler.ItemLeft) { PGPILeft = true; ItemLeft = true; } else if (PGPILeft) { PGPILeft = false; ItemLeft = false; } if (GamePadHandler.ItemRight) { PGPIRight = true; ItemRight = true; } else if (PGPIRight) { PGPIRight = false; ItemRight = false; } if (GamePadHandler.ItemUp) { PGPIUp = true; ItemUp = true; } else if (PGPIUp) { PGPIUp = false; ItemUp = false; } if (GamePadHandler.ItemDown) { PGPIDown = true; ItemDown = true; } else if (PGPIDown) { PGPIDown = false; ItemDown = false; } SprintOrWalk = GamePadHandler.SprintOrWalk; if (Sprint) { SprintOrWalk = 1; } if (Walk) { SprintOrWalk = -1; } while (Direction.Yaw < 0) { Direction.Yaw += 360; } while (Direction.Yaw > 360) { Direction.Yaw -= 360; } if (Direction.Pitch > 89.9f) { Direction.Pitch = 89.9f; } if (Direction.Pitch < -89.9f) { Direction.Pitch = -89.9f; } if (TheClient.VR != null) { OpenTK.Quaternion oquat = TheClient.VR.HeadMatRot.ExtractRotation(true); Quaternion quat = new Quaternion(oquat.X, oquat.Y, oquat.Z, oquat.W); Vector3 face = -Quaternion.Transform(Vector3.UnitZ, quat); Direction = Utilities.VectorToAngles(new Location(face)); //OpenTK.Vector3 headSpot = TheClient.VR.BasicHeadMat.ExtractTranslation(); if (TheClient.VR.Left != null) { if (TheClient.VR.Left.Trigger > 0.01f) { Location lforw = TheClient.VR.Left.ForwardVector(); Location ldir = Utilities.VectorToAngles(lforw); double goalyaw = ldir.Yaw - Direction.Yaw; Vector2 resmove = new Vector2(Math.Sin(goalyaw * Utilities.PI180), Math.Cos(goalyaw * Utilities.PI180)); double len = resmove.Length(); SprintOrWalk = (float)(len * 2.0 - 1.0); if (len > 1.0) { resmove /= len; } XMove = -(float)resmove.X; YMove = (float)resmove.Y; } if (TheClient.VR.Left.Pressed.HasFlag(VRButtons.SIDE_GRIP)) { Upward = true; PVRJump = true; } else { Upward = false; PVRJump = false; } } if (TheClient.VR.Right != null) { if (TheClient.VR.Right.Pressed.HasFlag(VRButtons.TRIGGER)) { Click = true; PVRPrimary = true; } else if (PVRPrimary) { Click = false; PVRPrimary = false; } if (TheClient.VR.Right.Pressed.HasFlag(VRButtons.MENU_BUTTON)) { AltClick = true; PVRSecondary = true; } else if (PVRSecondary) { AltClick = false; PVRSecondary = false; } if (TheClient.VR.Right.Pressed.HasFlag(VRButtons.SIDE_GRIP)) { Use = true; PVRUse = true; } else if (PVRUse) { Use = false; PVRUse = false; } bool rtppressed = TheClient.VR.Right.Pressed.HasFlag(VRButtons.TRACKPAD); OpenTK.Vector2 rtp = TheClient.VR.Right.TrackPad; float yxdiff = Math.Abs(rtp.Y) - Math.Abs(rtp.X); if (rtppressed && rtp.Y > 0.01 && (yxdiff > 0.01)) { ItemUp = true; PVRItemUp = true; } else if (PVRItemUp) { ItemUp = false; PVRItemUp = false; } if (rtppressed && rtp.Y < 0.01 && (yxdiff > 0.01)) { ItemDown = true; PVRItemDown = true; } else if (PVRItemDown) { ItemDown = false; PVRItemDown = false; } if (rtppressed && rtp.X > 0.01 && (yxdiff < -0.01)) { ItemRight = true; PVRItemRight = true; } else if (PVRItemRight) { ItemRight = false; PVRItemRight = false; } if (rtppressed && rtp.X < 0.01 && (yxdiff < -0.01)) { ItemLeft = true; PVRItemLeft = true; } else if (PVRItemLeft) { ItemLeft = false; PVRItemLeft = false; } bool rtptouched = TheClient.VR.Right.Touched.HasFlag(VRButtons.TRACKPAD); if (rtptouched && !VRRTouched) { VRRTouchDown = TheClient.VR.Right.TrackPad; VRRTouched = true; } if (rtptouched) { VRRTouchLast = TheClient.VR.Right.TrackPad; } const float VR_ADJMIN = 0.5f; if (!rtptouched && (VRRTouchLast.X != 0.0f || VRRTouchLast.Y != 0.0f)) { if (VRRTouchDown.X < -VR_ADJMIN && VRRTouchLast.X > VR_ADJMIN) { TheClient.Commands.ExecuteCommands("itemprev"); // TODO: Less lazy! } else if (VRRTouchDown.X > VR_ADJMIN && VRRTouchLast.X < -VR_ADJMIN) { TheClient.Commands.ExecuteCommands("itemnext"); // TODO: Less lazy! } if (VRRTouchDown.Y < -VR_ADJMIN && VRRTouchLast.Y > VR_ADJMIN) { TheClient.Commands.ExecuteCommands("echo 'Wow! You swiped up! Behavior for this coming SOON!'"); // TODO: Less lazy! } else if (VRRTouchDown.Y > VR_ADJMIN && VRRTouchLast.Y < -VR_ADJMIN) { TheClient.Commands.ExecuteCommands("weaponreload"); // TODO: Less lazy! } VRRTouchLast = OpenTK.Vector2.Zero; } } } TryToJump(); UpdateLocalMovement(); SetMoveSpeed(CBody); FlyForth(CBody, TheRegion.Delta); SetBodyMovement(CBody); PlayRelevantSounds(); MoveVehicle(); if (Flashlight != null) { Flashlight.Direction = Utilities.ForwardVector_Deg(Direction.Yaw, Direction.Pitch); Flashlight.Reposition(GetEyePosition() + Utilities.ForwardVector_Deg(Direction.Yaw, 0) * 0.3f); } base.Tick(); //base.SetOrientation(Quaternion.Identity); aHTime += TheClient.Delta; aTTime += TheClient.Delta; aLTime += TheClient.Delta; if (hAnim != null) { if (aHTime >= hAnim.Length) { aHTime = 0; } } if (tAnim != null) { if (aTTime >= tAnim.Length) { aTTime = 0; } } if (lAnim != null) { if (aLTime >= lAnim.Length) { aLTime = 0; } } bool hasjp = HasJetpack(); JPBoost = hasjp && ItemLeft; JPHover = hasjp && ItemRight; // TODO: Triggered by console opening/closing directly, rather than monitoring it on the tick? if (TheClient.Network.IsAlive) { if (UIConsole.Open && !ConsoleWasOpen) { TheClient.Network.SendPacket(new SetStatusPacketOut(ClientStatus.TYPING, 1)); ConsoleWasOpen = true; } else if (!UIConsole.Open && ConsoleWasOpen) { TheClient.Network.SendPacket(new SetStatusPacketOut(ClientStatus.TYPING, 0)); ConsoleWasOpen = false; } } }
public void GetFlashlightType() { var flashlight = new Flashlight("Test"); Assert.AreEqual("Test", flashlight.GetFlashlightType()); }
public abstract void HandlePower(Flashlight context);
// Use this for initialization void Start() { sceneLightCount = 0; allLights = new Light[50]; spotLight = GetComponentInChildren<Flashlight>(); faceUiLarge = GameObject.Find("FaceUILarge"); largeUiText = faceUiLarge.GetComponentInChildren<Text>(); faceUiLarge.SetActive(false); faceUiSmall = GameObject.Find("FaceUISmall"); smallUiText = faceUiSmall.GetComponentInChildren<Text>(); faceUiSmall.SetActive(false); faceUiHint = GameObject.Find("FaceUIHint"); hintText = faceUiHint.GetComponentInChildren<Text>(); faceUiHint.SetActive(false); heartBeat = GameObject.Find("Heartbeat").GetComponent<AudioSource>(); SanitySystem.init(this); ghouls = GameObject.FindGameObjectsWithTag("ghoul"); foreach (GameObject ghoul in ghouls) { ghoul.SetActive(false); } GameObject[] allItems = GameObject.FindGameObjectsWithTag("item"); foreach(GameObject go in allItems) { if(go.GetComponentInChildren<Light>() != null) { allLights[sceneLightCount++] = go.GetComponentInChildren<Light>(); } } Debug.Log("Found a total of " + sceneLightCount + " lights in the scene."); spotLight.toggleLight(); }
void SpawnFlashlight() { flashlight = (Flashlight)flashlight_prefab.Instance(); GetParent().CallDeferred("add_child", flashlight); }
public override void HandlePower(Flashlight contextFlashlight) { contextFlashlight.LightSolid(); contextFlashlight.SetState(new FlashlightStateOn()); }
public abstract void HandlePower(Flashlight contextFlashlight);
public abstract void OnEnter(Flashlight flashlight);
public virtual void HandlePower(Flashlight context) { }
public virtual void HandlePowerPressed(Flashlight flashlight) { }
public virtual void OnEnter(Flashlight context) { }
public override void HandlePower(Flashlight context) { }
public static async void TurnOff() { await Flashlight.TurnOffAsync(); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.activity_main); var coordinates = FindViewById <TextView>(Resource.Id.textView1); var getlocation = FindViewById <Button>(Resource.Id.button1); var batteryinfo = FindViewById <Button>(Resource.Id.button2); var batterystats = FindViewById <TextView>(Resource.Id.textView2); Switch s = FindViewById <Switch>(Resource.Id.switch1); getlocation.Click += async delegate { try { var request = new GeolocationRequest(GeolocationAccuracy.Best); var location = await Geolocation.GetLocationAsync(request); if (location != null) { Console.WriteLine($"Latitude: {location.Latitude}, Longitude: {location.Longitude}, Altitude: {location.Altitude}"); //var lat = location.Latitude.ToString; coordinates.Text = location.Latitude + " " + location.Longitude; } } catch (FeatureNotSupportedException fnsEx) { // Handle not supported on device exception } catch (FeatureNotEnabledException fneEx) { // Handle not enabled on device exception } catch (PermissionException pEx) { // Handle permission exception } catch (Exception ex) { // Unable to get location } }; s.CheckedChange += async delegate(object sender, CompoundButton.CheckedChangeEventArgs e) { var toast = Toast.MakeText(this, "Flashlight is " + (e.IsChecked ? "on" : "off"), ToastLength.Short); toast.Show(); if (s.Checked == true) { try { // Turn On await Flashlight.TurnOnAsync(); } catch (FeatureNotSupportedException fnsEx) { // Handle not supported on device exception } catch (PermissionException pEx) { // Handle permission exception } catch (Exception ex) { // Unable to turn on/off flashlight } } else { try { // Turn Off await Flashlight.TurnOffAsync(); } catch (FeatureNotSupportedException fnsEx) { // Handle not supported on device exception } catch (PermissionException pEx) { // Handle permission exception } catch (Exception ex) { // Unable to turn on/off flashlight } } }; batteryinfo.Click += delegate { var level = Battery.ChargeLevel; // returns 0.0 to 1.0 or 1.0 when on AC or no battery. var state = Battery.State; switch (state) { case BatteryState.Charging: // Currently charging break; case BatteryState.Full: // Battery is full break; case BatteryState.Discharging: case BatteryState.NotCharging: // Currently discharging battery or not being charged break; case BatteryState.NotPresent: // Battery doesn't exist in device (desktop computer) case BatteryState.Unknown: // Unable to detect battery state break; } var source = Battery.PowerSource; switch (source) { case BatteryPowerSource.Battery: // Being powered by the battery break; case BatteryPowerSource.AC: // Being powered by A/C unit break; case BatteryPowerSource.Usb: // Being powered by USB cable break; case BatteryPowerSource.Wireless: // Powered via wireless charging break; case BatteryPowerSource.Unknown: // Unable to detect power source break; } batterystats.Text = "Level: " + level + "\n" + "State: " + state + "\n" + "PowerSource: " + source; }; }
public override void OnEnter(Flashlight f) { f.LightOff(); }
public virtual void ModePressed(Flashlight context) { }
public override void HandlePower(Flashlight f) { f.SetState(onState); }
public override void HandlePower(Flashlight context) { context.LightOff(); context.SetState(new Off()); }
public override void HandleMode(Flashlight f) { throw new System.NotImplementedException(); }
public override void ModePressed(Flashlight context) { context.solidLED(); context.SetState(new FLASHING()); }
private void Awake() { instance = this; }
public override void OnEnter(Flashlight context) { }
protected override async void OnStart() { await Flashlight.TurnOnAsync(); }
public SmallFlashlight() { flashlight = new Flashlight("Small"); }
protected override async void OnSleep() { await Flashlight.TurnOffAsync(); }