/// <summary> /// Event callback to set proper alarm tone value /// </summary> /// <param name="sender">Event object sender</param> /// <param name="e">Event argument</param> private void ToneRadio_Selected(object sender, SelectedEventArgs e) { RadioButton button = sender as RadioButton; if (button.IsSelected) { switch (button.Text) { case "Default": newValue = AlarmToneTypes.Default; break; case "AlarmMp3": newValue = AlarmToneTypes.AlarmMp3; break; case "RingtoneSdk": newValue = AlarmToneTypes.RingtoneSdk; break; default: newValue = AlarmToneTypes.Default; break; } } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { AlarmToneTypes flag = (AlarmToneTypes)value; if (flag == AlarmToneTypes.AlarmMp3) { return("alarm.mp3"); } else if (flag == AlarmToneTypes.RingtoneSdk) { return("Sdk"); } else { return("Default"); } }
/// <summary> /// Asynchronously plays ringing sound /// </summary> /// <param name="targetVolume">The volume level at playing</param> /// <param name="toneTypes">AlarmToneTypes to play</param> async public void PlaySound(float targetVolume, AlarmToneTypes toneTypes) { audioStreamPolicy = new AudioStreamPolicy(AudioStreamType.Alarm); audioStreamPolicy.AcquireFocus(AudioStreamFocusOptions.Playback, AudioStreamBehaviors.NoResume, null); player = new Player(); MediaUriSource soudSource = new MediaUriSource(SystemSettings.IncomingCallRingtone); player.SetSource(soudSource); player.ApplyAudioStreamPolicy(audioStreamPolicy); await player.PrepareAsync(); player.IsLooping = true; player.Volume = targetVolume; if (player.State == PlayerState.Ready) { player.Start(); } }
/// <summary> /// This method is called when this page is being shown after creation /// </summary> internal void Update() { AlarmToneTypes type = AlarmModel.BindableAlarmRecord.AlarmToneType; switch (type) { case AlarmToneTypes.Default: ((AlarmToneRow)defaultTone.View).toneRadio.IsSelected = true; break; case AlarmToneTypes.AlarmMp3: ((AlarmToneRow)alarmMP3Tone.View).toneRadio.IsSelected = true; break; case AlarmToneTypes.RingtoneSdk: ((AlarmToneRow)ringtoneMP3Tone.View).toneRadio.IsSelected = true; break; default: break; } }
/// <summary> /// Construct alarm tone row UI /// </summary> /// <param name="editType">type indicator</param> /// <seealso cref="AlarmToneTypes"> public AlarmToneRow(AlarmToneTypes type) { /// Sets each row height to 120 according UX guide HeightRequest = 120; /// Checks type and set mainStr switch (type) { case AlarmToneTypes.AlarmMp3: mainStr = "alarm.mp3"; break; case AlarmToneTypes.Default: mainStr = "Default"; break; case AlarmToneTypes.RingtoneSdk: mainStr = "ringtone_sdk.mp3"; break; default: mainStr = ""; break; } /// If mainStr is not null, create a new main Label if (mainStr != null) { if (mainLabel == null) { mainLabel = new Label { HeightRequest = 54, Style = AlarmStyle.T033, }; // to meet To meet thin attribute for font, need to use custom feature FontFormat.SetFontWeight(mainLabel, FontWeight.Light); } /// Sets main Label with mainStr mainLabel.Text = mainStr; /// Add to layout Children.Add(mainLabel, Constraint.RelativeToParent((parent) => { return(32); }), Constraint.RelativeToParent((parent) => { return((120 - 72) / 2); })); } /// Create a new radio button for this row toneRadio = new RadioButton { Text = type.ToString(), HeightRequest = 80, WidthRequest = 80, /// Group name should be set same for all radio button group elements GroupName = "AlarmTone", }; if (AlarmModel.BindableAlarmRecord.AlarmToneType == type) { toneRadio.IsSelected = true; oldValue = newValue = type; } toneRadio.Selected += ToneRadio_Selected; Children.Add(toneRadio, Constraint.RelativeToParent((parent) => (parent.X + parent.Width - (80 + 32))), Constraint.RelativeToParent((parent) => { return((120 - 80) / 2); })); }
/// <summary> /// Constructor for this class /// Sets proper controls to this class /// </summary> /// <param name="type">The type of alarm tone.</param> /// <seealso cref="AlarmToneTypes"> /// <param name="page">The content page which includes this table view cell</param> /// <seealso cref="ContentPage"> public AlarmToneTableCell(AlarmToneTypes type, ContentPage page) { Type = type; Container = page; View = new AlarmToneRow(type); }
/// <summary> /// Converting source value to target value /// </summary> /// <param name="value">Source object</param> /// <seealso cref="System.object"> /// <param name="targetType">The target type to convert</param> /// <seealso cref="Type"> /// <param name="CultureInfo">The culture info</param> /// <seealso cref="CultureInfo"> /// <returns>Returns converted string</returns> public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { // Check alarm type if (value.GetType() == typeof(AlarmTypes)) { AlarmTypes modelValue = (AlarmTypes)value; string s = ""; switch (modelValue) { // case of sound type case AlarmTypes.Sound: s = "Sound"; break; // case of vibration type case AlarmTypes.Vibration: s = "Vibration"; break; // case of sound and vibration case AlarmTypes.SoundVibration: s = "Vibration and sound"; break; } return(s); } // Check alarm tone type else if (value.GetType() == typeof(AlarmToneTypes)) { AlarmToneTypes modelValue = (AlarmToneTypes)value; string s = ""; switch (modelValue) { // case of default case AlarmToneTypes.Default: s = "Default"; break; // case of alarm mp3 case AlarmToneTypes.AlarmMp3: s = "alarm.mp3"; break; // case of rington sdk case AlarmToneTypes.RingtoneSdk: s = "ringtone_sdk.mp3"; break; } return(s); } else if (value.GetType() == typeof(AlarmWeekFlag)) { string s = ""; AlarmWeekFlag flag = (AlarmWeekFlag)value; // case of week flag never if (flag == AlarmWeekFlag.Never) { // case of never s = "Never"; } // case of all days else if (flag == AlarmWeekFlag.AllDays) { // case of everyday s = "Everyday"; } // case of week other else { for (int i = 1; i < 7; i++) { int mask = 1 << i; if (((int)flag & mask) > 0) { switch (mask) { case (int)AlarmWeekFlag.Monday: s += "Mon "; break; case (int)AlarmWeekFlag.Tuesday: s += "Tue "; break; case (int)AlarmWeekFlag.Wednesday: s += "Wed "; break; case (int)AlarmWeekFlag.Thursday: s += "Thu "; break; case (int)AlarmWeekFlag.Friday: s += "Fri "; break; case (int)AlarmWeekFlag.Saturday: s += "Sat "; break; } } } if (((int)flag & 0x1) > 0) { s += "Sun "; } } return(s); } else { return(null); } }