Advertisement
Guest User

Untitled

a guest
Jun 8th, 2018
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.20 KB | None | 0 0
  1. private Image[] _images;
  2. private Image[] _previewImages;
  3. private ImageSource[] _imageSources;
  4.  
  5. public ShowRoomPage()
  6. {
  7. InitializeComponent();
  8.  
  9. Loading(true);
  10.  
  11. /Other stuff leightweight
  12.  
  13.  
  14. //var scheduler = TaskScheduler.FromCurrentSynchronizationContext();
  15. Task.Factory.StartNew(() =>
  16. {
  17. Thread.Sleep(5000);
  18. int count = InitializeImages();
  19.  
  20. return count;
  21. }).ContinueWith(r =>
  22. {
  23. Device.BeginInvokeOnMainThread(async () =>
  24. {
  25. if (r.Result == GlobalSettings.ImageCount)
  26. ButtonsGrid.ColumnDefinitions[1].Width = 0;
  27. else
  28. ButtonsGrid.ColumnDefinitions[1].Width = GridLength.Star;
  29.  
  30. for (int i = 0; i < r.Result; i++)
  31. {
  32. ImagesGrid.Children.Add(_previewImages[i]);
  33. ImagesStackLayout.Children.Add(_images[i]);
  34. }
  35. await ShowWallpaperInPreview();
  36.  
  37. await Loading(false);
  38. });
  39. });
  40. }
  41.  
  42. private int InitializeImages()
  43. {
  44. int lastImageIndex = GlobalSettings.ImageCount - GlobalSettings.PremiumCount + GlobalSettings.Unlocked;
  45.  
  46. _images = new Image[lastImageIndex];
  47. _previewImages = new Image[lastImageIndex];
  48. _imageSources = new ImageSource[lastImageIndex];
  49.  
  50. //Foreach not premium wallpaper image
  51. for (int i = 0; i < lastImageIndex; i++)
  52. {
  53. //Create the path
  54. var path = "Wallpaper.Images.Wallpapers.W" + i + ".jpg";
  55.  
  56. //Create images
  57. _imageSources[i] = ImageSource.FromResource(path);
  58. _images[i] = new Image()
  59. {
  60. Source = _imageSources[i],
  61. Scale = 0.95,
  62. Opacity = 0.75
  63. };
  64. _previewImages[i] = new Image()
  65. {
  66. Source = _imageSources[i],
  67. Opacity = 0
  68. };
  69.  
  70. //Event when user taps on the image
  71. int index = i;
  72. var tgr = new TapGestureRecognizer();
  73. tgr.Tapped += async (sender, args) =>
  74. {
  75. if (!_canInteract)
  76. return;
  77.  
  78. _canInteract = false;
  79.  
  80. //Show the image in the preview
  81. _selectedImage = index;
  82. await ShowWallpaperInPreview();
  83.  
  84. _canInteract = true;
  85. };
  86.  
  87. _images[i].GestureRecognizers.Add(tgr);
  88. }
  89.  
  90. return lastImageIndex;
  91. }
  92.  
  93. private async Task Loading(bool value)
  94. {
  95. if (value)
  96. {
  97. //Hide the view
  98. _canInteract = false;
  99. MainGrid.IsVisible = false;
  100. MainActivityIndicator.IsRunning = true;
  101. }
  102. else
  103. {
  104. //Fade in the view
  105. MainActivityIndicator.IsRunning = false;
  106. MainGrid.Opacity = 0;
  107. MainGrid.IsVisible = true;
  108. await MainGrid.FadeTo(1, 800);
  109. _canInteract = true;
  110. }
  111. }
  112.  
  113. <?xml version="1.0" encoding="utf-8" ?>
  114. <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
  115. xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
  116. x:Class="Wallpaper.ShowRoomPage"
  117. xmlns:ads="clr-namespace:Wallpaper.Controls;assembly=Wallpaper"
  118. Title="Wallpapers">
  119. <ContentPage.Content>
  120. <Grid BackgroundColor="{StaticResource BackgroundColor}">
  121. <!--Activity Indicator-->
  122. <ActivityIndicator x:Name="MainActivityIndicator" HorizontalOptions="Center" VerticalOptions="Center" WidthRequest="45" HeightRequest="45" Color="{StaticResource SecondAccentColor}"/>
  123.  
  124. <Grid x:Name="MainGrid">
  125. <Grid.RowDefinitions>
  126. <RowDefinition Height="35"/>
  127. <RowDefinition Height="21"/>
  128. <RowDefinition Height="4*"/>
  129. <RowDefinition Height="21"/>
  130. <RowDefinition Height="*"/>
  131. <RowDefinition Height="10"/>
  132. <RowDefinition Height="40"/>
  133. <RowDefinition Height="Auto"/>
  134. </Grid.RowDefinitions>
  135.  
  136. <!--Preview image-->
  137. <Grid x:Name="ImagesGrid" Grid.Row="2">
  138. <Image x:Name="PreviewImage"/>
  139. </Grid>
  140.  
  141. <!--All images-->
  142. <ScrollView Grid.Row="4" Orientation="Horizontal" HorizontalScrollBarVisibility="Never">
  143. <StackLayout x:Name="ImagesStackLayout" Spacing="10" Orientation="Horizontal"/>
  144. </ScrollView>
  145. </Grid>
  146. </Grid>
  147. </ContentPage.Content>
  148. </ContentPage>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement