From f3ad2c07c16a3f51e5aba57c38cbcdf210ed10af Mon Sep 17 00:00:00 2001 From: Nicolas Jager <nicolas.jager@savoirfairelinux.com> Date: Wed, 26 Oct 2016 13:39:03 -0400 Subject: [PATCH] profil : allows to take a picture by clicking on the avatar Change-Id: I8da2ece803a90981a1ccea352df9f6f2ed084535 Tuleap: #1250 --- SmartPanel.xaml | 23 ++++++++++++++++ SmartPanel.xaml.cpp | 66 +++++++++++++++++++++++++++++++++++++++++++++ SmartPanel.xaml.h | 3 +++ Styles.xaml | 13 +++++++++ 4 files changed, 105 insertions(+) diff --git a/SmartPanel.xaml b/SmartPanel.xaml index 8773b59..df28080 100644 --- a/SmartPanel.xaml +++ b/SmartPanel.xaml @@ -379,6 +379,11 @@ Height="80" Width="80" Grid.Column="0" + Stroke="White" + StrokeThickness="3" + PointerEntered="_selectedAccountAvatarContainer__PointerEntered" + PointerExited="_selectedAccountAvatarContainer__PointerExited" + PointerReleased="_selectedAccountAvatarContainer__PointerReleased" Margin="5"> <Ellipse.Fill> <ImageBrush @@ -386,6 +391,24 @@ ImageSource="Assets\TESTS\contactAvatar.png"/> </Ellipse.Fill> </Ellipse> + <Ellipse + x:Name="_shaderPhotoboothIcon_" + Visibility="Collapsed" + Height="80" + Width="80" + Grid.Column="0" + IsHitTestVisible="False" + Fill="Black" + Opacity="0.3" + Margin="5"> + </Ellipse> + <TextBlock x:Name="_photoboothIcon_" + Grid.Column="0" + Visibility="Collapsed" + IsHitTestVisible="False" + Style="{StaticResource TextSegoeStyle-Centered-40pt-white}" + Text=""> + </TextBlock> <StackPanel Grid.Column="1" VerticalAlignment="Bottom"> <TextBlock x:Name="_selectedAccountName_" diff --git a/SmartPanel.xaml.cpp b/SmartPanel.xaml.cpp index caf31bd..a93d42e 100644 --- a/SmartPanel.xaml.cpp +++ b/SmartPanel.xaml.cpp @@ -206,17 +206,20 @@ void RingClientUWP::Views::SmartPanel::setMode(RingClientUWP::Views::SmartPanel: if (mode == RingClientUWP::Views::SmartPanel::Mode::Normal) { _rowRingTxtBx_->Height = 40; _selectedAccountAvatarContainer_->Height = 80; + _shaderPhotoboothIcon_->Height = 80; _selectedAccountAvatarColumn_->Width = 90; _selectedAccountRow_->Height = 90; } else { _rowRingTxtBx_->Height = 0; _selectedAccountAvatarContainer_->Height = 50; + _shaderPhotoboothIcon_->Height = 50; _selectedAccountAvatarColumn_->Width = 60; _selectedAccountRow_->Height = 60; } _selectedAccountAvatarContainer_->Width = _selectedAccountAvatarContainer_->Height; + _shaderPhotoboothIcon_->Width = _shaderPhotoboothIcon_->Height; _settingsTBtn_->IsChecked = false; _accountsMenuButton_->IsChecked = false; _shareMenuButton_->IsChecked = false; @@ -858,3 +861,66 @@ Object ^ RingClientUWP::Views::CollapseEmptyString::ConvertBack(Object ^ value, RingClientUWP::Views::CollapseEmptyString::CollapseEmptyString() {} + + +void RingClientUWP::Views::SmartPanel::_selectedAccountAvatarContainer__PointerEntered(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e) +{ + _photoboothIcon_->Visibility = Windows::UI::Xaml::Visibility::Visible; + _shaderPhotoboothIcon_->Visibility = Windows::UI::Xaml::Visibility::Visible; +} + + +void RingClientUWP::Views::SmartPanel::_selectedAccountAvatarContainer__PointerReleased(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e) +{ + CameraCaptureUI^ cameraCaptureUI = ref new CameraCaptureUI(); + cameraCaptureUI->PhotoSettings->Format = CameraCaptureUIPhotoFormat::Png; + cameraCaptureUI->PhotoSettings->CroppedSizeInPixels = Size(100, 100); + + create_task(cameraCaptureUI->CaptureFileAsync(CameraCaptureUIMode::Photo)) + .then([this](StorageFile^ photoFile) + { + if (photoFile != nullptr) { + // maybe it would be possible to move some logics to the style sheet + auto brush = ref new ImageBrush(); + + auto circle = ref new Ellipse(); + circle->Height = 80; // TODO : use some global constant when ready + circle->Width = 80; + auto path = photoFile->Path; + auto uri = ref new Windows::Foundation::Uri(path); + auto bitmapImage = ref new Windows::UI::Xaml::Media::Imaging::BitmapImage(); + bitmapImage->UriSource = uri; + + StorageFolder^ localfolder = ApplicationData::Current->LocalFolder; + String^ profilefolder = ".profile"; + create_task(localfolder->CreateFolderAsync(profilefolder, + Windows::Storage::CreationCollisionOption::OpenIfExists)) + .then([=](StorageFolder^ copytofolder) { + try { + create_task(photoFile->CopyAsync(copytofolder)) + .then([=](StorageFile^ copiedfile) { + copiedfile->RenameAsync("profile_image.png", + Windows::Storage::NameCollisionOption::ReplaceExisting); + }); + } + catch (Exception^ e) { + RingDebug::instance->print("Exception while saving profile image"); + } + }); + + Configuration::UserPreferences::instance->PREF_PROFILE_PHOTO = true; + + Configuration::UserPreferences::instance->save(); + + brush->ImageSource = bitmapImage; + _selectedAccountAvatar_->ImageSource = bitmapImage; + } + }); +} + + +void RingClientUWP::Views::SmartPanel::_selectedAccountAvatarContainer__PointerExited(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e) +{ + _photoboothIcon_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; + _shaderPhotoboothIcon_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; +} diff --git a/SmartPanel.xaml.h b/SmartPanel.xaml.h index 2419ee7..3267255 100644 --- a/SmartPanel.xaml.h +++ b/SmartPanel.xaml.h @@ -133,6 +133,9 @@ private: void _passwordBoxAccountCreationCheck__PasswordChanged(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void _accountTypeComboBox__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e); void _ringAliasTextBox__TextChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::TextChangedEventArgs^ e); + void _selectedAccountAvatarContainer__PointerEntered(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e); + void _selectedAccountAvatarContainer__PointerReleased(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e); + void _selectedAccountAvatarContainer__PointerExited(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e); }; } } \ No newline at end of file diff --git a/Styles.xaml b/Styles.xaml index 8dc3475..ddcba01 100644 --- a/Styles.xaml +++ b/Styles.xaml @@ -117,6 +117,19 @@ <Setter Property="Foreground" Value="Black"/> </Style> + <Style x:Key="TextSegoeStyle-Centered-40pt-white" + TargetType="TextBlock"> + <Setter Property="FontFamily" + Value="Segoe MDL2 Assets"/> + <Setter Property="FontSize" + Value="40"/> + <Setter Property="HorizontalAlignment" + Value="Center"/> + <Setter Property="VerticalAlignment" + Value="Center"/> + <Setter Property="Foreground" + Value="White"/> + </Style> <Style x:Key="ButtonStyle1" TargetType="Button"> <Setter Property="Width" -- GitLab