/// <summary> /// Sets the theme for the app. /// </summary> async Task SetAppTheme(AppThemeViewModel theme) { try { Application.Current.UserAppTheme = theme.Key; Settings.AppTheme = theme.Key; foreach (var item in AppThemes) { item.IsSelected = false; } AppThemes.FirstOrDefault(x => x.Key == Settings.AppTheme).IsSelected = true; RaisePropertyChanged(nameof(AppThemes)); //var statusBar = DependencyService.Get<IStatusBar>(); //statusBar?.SetStatusBarColor((OSAppTheme)theme.Key, Color.Black); HapticFeedback.Perform(HapticFeedbackType.Click); AnalyticsService.Track("App Theme Changed", nameof(theme), ((OSAppTheme)theme.Key).ToString() ?? "null"); } catch (Exception ex) { await DialogService.AlertAsync(Translations.error_couldntchangetheme, Translations.error_title, Translations.ok).ConfigureAwait(false); AnalyticsService.Report(ex); } }
/// <summary> /// Deletes a contribution. /// </summary> async Task DeleteContribution() { try { // Shouldn't be getting here anyway, so no need for a message. if (!CanBeEdited) { return; } if (!await VerifyInternetConnection()) { return; } // Ask for confirmation before deletion. var confirm = await DialogService.ConfirmAsync(Translations.contributiondetail_deleteconfirmation, Translations.warning_title, Translations.ok, Translations.cancel).ConfigureAwait(false); if (!confirm) { return; } State = LayoutState.Loading; var isDeleted = await MvpApiService.DeleteContributionAsync(Contribution); if (isDeleted) { // TODO: Pass back true to indicate it needs to refresh. // TODO: Be a bit more sensible with muh threads plz. MainThread.BeginInvokeOnMainThread(() => HapticFeedback.Perform(HapticFeedbackType.LongPress)); AnalyticsService.Track("Contribution Deleted"); await MainThread.InvokeOnMainThreadAsync(() => BackAsync()); //MessagingService.Current.SendMessage(MessageKeys.HardRefreshNeeded); MessagingService.Current.SendMessage(MessageKeys.HardRefreshNeeded); } else { await DialogService.AlertAsync(Translations.contributiondetail_notdeleted, Translations.error_title, Translations.ok).ConfigureAwait(false); } } catch (Exception ex) { AnalyticsService.Report(ex); await DialogService.AlertAsync(Translations.error_unexpected, Translations.error_title, Translations.ok).ConfigureAwait(false); } finally { State = LayoutState.None; } }
public static void HapticFeedbackLongPress() { try { // Perform click feedback HapticFeedback.Perform(HapticFeedbackType.LongPress); } catch (FeatureNotSupportedException ex) { // Feature not supported on device } catch (Exception ex) { // Other error has occurred. } }
async void Button_Clicked2(System.Object sender, System.EventArgs e) { try { // Haptic HapticFeedback.Perform(HapticFeedbackType.Click); } catch (FeatureNotSupportedException ex) { await DisplayAlert("Sorry", "No can do amigo - no device support", "Ok"); } catch (Exception ex) { await DisplayAlert("Ooops", ex.Message, "Ok"); } }
private void IsCheckedChanged(bool isChecked) { Todo.Completed = isChecked; try { HapticFeedback.Perform(HapticFeedbackType.Click); } catch (FeatureNotSupportedException ex) { Console.WriteLine($"Haptics not supported.{Environment.NewLine}{ex.Message}{Environment.NewLine}{ex.StackTrace}"); } catch (Exception ex) { Console.WriteLine($"{ex.Message}{Environment.NewLine}{ex.StackTrace}"); } StateHasChanged(); }
private async void ButtonTimer_Elapsed(object sender, ElapsedEventArgs e) { if (_elements == null) { return; } _elements.Index = LeftRightButton ? _elements.MaxElement() : 0; try { HapticFeedback.Perform(HapticFeedbackType.LongPress); } catch (FeatureNotSupportedException) { Vibration.Vibrate(100); } await Device.InvokeOnMainThreadAsync(() => RefreshPage(false)).ConfigureAwait(false); }
/// <summary> /// Sets the app icon to whatever the user chose. /// </summary> async Task SetAppIcon(AppIconViewModel icon) { try { var iconSwitcher = DependencyService.Get <IIconService>(); if (iconSwitcher == null) { return; } if (icon.Key == AppIcon.Default) { await iconSwitcher?.SwitchAppIcon(null); } else { await iconSwitcher?.SwitchAppIcon(icon.Key.ToString()); } Settings.AppIcon = icon.Key; foreach (var item in AppIcons) { item.IsSelected = false; } AppIcons.FirstOrDefault(x => x.Key == Settings.AppIcon).IsSelected = true; RaisePropertyChanged(nameof(AppIcons)); HapticFeedback.Perform(HapticFeedbackType.Click); AnalyticsService.Track("App Icon Changed", nameof(icon), icon.Key.ToString() ?? "null"); } catch (Exception ex) { await DialogService.AlertAsync(Translations.error_couldntchangeicon, Translations.error_title, Translations.ok).ConfigureAwait(false); AnalyticsService.Report(ex); } }
/// <summary> /// Saves a contribution. /// </summary> async Task SaveContribution() { try { if (!await VerifyInternetConnection()) { return; } if (!Contribution.IsValid()) { IsContributionValid = false; return; } IsContributionValid = true; State = LayoutState.Saving; if (IsEditing) { var result = await MvpApiService.UpdateContributionAsync(Contribution.ToContribution()); if (!result) { await DialogService.AlertAsync(Translations.error_couldntsavecontribution, Translations.error_title, Translations.ok).ConfigureAwait(false); return; } MainThread.BeginInvokeOnMainThread(() => HapticFeedback.Perform(HapticFeedbackType.LongPress)); AnalyticsService.Track("Contribution Added"); await CloseModalAsync().ConfigureAwait(false);; await BackAsync().ConfigureAwait(false); MessagingService.Current.SendMessage(MessageKeys.RefreshNeeded); } else { var result = await MvpApiService.SubmitContributionAsync(Contribution.ToContribution()); if (result == null) { await DialogService.AlertAsync(Translations.error_couldntsavecontribution, Translations.error_title, Translations.ok).ConfigureAwait(false); return; } AnalyticsService.Track("Contribution Edited"); MainThread.BeginInvokeOnMainThread(() => HapticFeedback.Perform(HapticFeedbackType.LongPress)); await CloseModalAsync().ConfigureAwait(false); MessagingService.Current.SendMessage(MessageKeys.RefreshNeeded); } } catch (Exception ex) { AnalyticsService.Report(ex); await DialogService.AlertAsync(Translations.error_couldntsavecontribution, Translations.error_title, Translations.ok).ConfigureAwait(false); } finally { State = LayoutState.None; } }
/// <summary> /// Handles when the language has been changed. /// </summary> void LanguageService_PreferredLanguageChanged(object sender, string e) { LoadLanguages(); HapticFeedback.Perform(HapticFeedbackType.Click); }
public void performHapticFeedback() { HapticFeedback.Perform(HapticFeedbackType.Click); }
public void LongPress() => HapticFeedback.Perform(HapticFeedbackType.LongPress);
public void Click() => HapticFeedback.Perform(HapticFeedbackType.Click);