Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Xamarin.Forms;
  7. using ThoughtCastRewrite.Models;
  8. using CarouselView.FormsPlugin.Abstractions;
  9.  
  10. using System.Collections.ObjectModel;
  11. using System.ComponentModel;
  12.  
  13. namespace ThoughtCastRewrite
  14. {
  15. public partial class MainPage : ContentPage
  16. {
  17.  
  18. OnboardingPageVm _onBoardingVm;
  19. public MainPage()
  20. {
  21.  
  22.  
  23. InitializeComponent();
  24.  
  25.  
  26. Title = "Carousel View";
  27. _onBoardingVm = new OnboardingPageVm();
  28. BindingContext = _onBoardingVm;
  29.  
  30. CarouselViewControl carouselView = new CarouselViewControl
  31. {
  32. VerticalOptions = LayoutOptions.FillAndExpand,
  33. HorizontalOptions = LayoutOptions.FillAndExpand,
  34. ShowIndicators = true
  35. };
  36.  
  37. var onBoardingDataTemplate = new DataTemplate(CreateViewTemplate);
  38. carouselView.ItemTemplate = onBoardingDataTemplate;
  39.  
  40. Grid mainContainer = new Grid { };
  41.  
  42. mainContainer.Children.Add(carouselView, 0, 0);
  43.  
  44. Content = mainContainer;
  45.  
  46. #region Bindings
  47.  
  48. carouselView.SetBinding(CarouselViewControl.ItemsSourceProperty, nameof(_onBoardingVm.BoardingObjectsList));
  49.  
  50. #endregion
  51.  
  52.  
  53.  
  54.  
  55. }
  56.  
  57. View CreateViewTemplate()
  58. {
  59.  
  60. var view = new StackLayout
  61. {
  62. BindingContext = _onBoardingVm.BoardingObjectsList
  63. };
  64.  
  65.  
  66. Button buttonToMain = new Button { Text = "Connect to Sensor Board" };
  67.  
  68. buttonToMain.Clicked += ButtonToMain_Clicked;
  69.  
  70. var buttonnew = new Image
  71.  
  72. {
  73. Aspect = Aspect.AspectFill,
  74.  
  75. };
  76.  
  77.  
  78.  
  79.  
  80.  
  81. view.Children.Add(buttonnew);
  82. view.Children.Add(buttonToMain);
  83.  
  84.  
  85.  
  86. view.SetBinding(BackgroundColorProperty, nameof(OnboardingModel.Color));
  87. return view;
  88. }
  89.  
  90. private void ButtonToMain_Clicked(object sender, EventArgs e)
  91. {
  92. this.Content = CreateViewTemplateMain();
  93.  
  94. }
  95.  
  96.  
  97. View CreateBluetoothTemplate()
  98. {
  99.  
  100. var view = new StackLayout
  101. {
  102. BackgroundColor = Color.FromHex("#292929"),
  103.  
  104. BindingContext = _onBoardingVm.BoardingObjectsList
  105. };
  106.  
  107.  
  108. var labelDevicesList = new Label()
  109. {
  110. Text = "Devices List"
  111. };
  112.  
  113. BluetoothInfo listBluetoothDevices = DependencyService.Get<BluetoothInfo>();
  114.  
  115.  
  116. var listView = new ListView();
  117. listView.ItemsSource = listBluetoothDevices.bluetoothDevices();
  118.  
  119.  
  120.  
  121. view.Children.Add(labelDevicesList);
  122. view.Children.Add(listView);
  123.  
  124.  
  125. return view;
  126. }
  127. View CreateViewTemplateMain()
  128. {
  129.  
  130.  
  131. var view = new StackLayout
  132. {
  133. BackgroundColor = Color.FromHex("#292929"),
  134.  
  135. BindingContext = _onBoardingVm.BoardingObjectsList
  136. };
  137.  
  138.  
  139.  
  140.  
  141.  
  142. var grid = new Grid();
  143.  
  144. grid.HorizontalOptions = LayoutOptions.Center;
  145. grid.VerticalOptions = LayoutOptions.CenterAndExpand;
  146.  
  147.  
  148. grid.RowDefinitions.Add(new RowDefinition { Height = 55 });
  149. // grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
  150. grid.ColumnDefinitions.Add(new ColumnDefinition { Width = 150 });
  151. // grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158. Image imageBrainLogo = new Image
  159. {
  160. HeightRequest = 400,
  161.  
  162. };
  163.  
  164.  
  165.  
  166.  
  167. view.Children.Add(imageBrainLogo);
  168.  
  169. imageBrainLogo.Source = ImageSource.FromResource("ThoughtCastRewrite.Thoughtcast.png");
  170.  
  171. Label labelConnectionStatus = new Label
  172. {
  173. Text = "Disconnected",
  174. FontSize = 8,
  175. HorizontalTextAlignment = TextAlignment.Center,
  176. TextColor = Color.Red
  177. };
  178.  
  179. Button buttonConnectToSensorBoard = new Button
  180. {
  181. Text = "Connect to Sensor Board",
  182. FontSize = 8,
  183. BorderColor = Color.White,
  184. BorderWidth = 1,
  185. BackgroundColor = Color.FromHex("#292929"),
  186. WidthRequest = 5,
  187. HeightRequest = 35,
  188. TextColor = Color.White
  189. };
  190.  
  191.  
  192. buttonConnectToSensorBoard.Clicked += ButtonConnectToSensorBoard_Clicked;
  193.  
  194. Button buttonDrawingMode = new Button
  195. {
  196. Text = "Drawing Mode",
  197. FontSize = 8,
  198. BackgroundColor = Color.FromHex("#454645"),
  199. WidthRequest = 5,
  200. HeightRequest = 35,
  201. TextColor = Color.White
  202. };
  203.  
  204. Button buttonZoneMode = new Button
  205. {
  206. Text = "Zone Mode",
  207. FontSize = 8,
  208. BackgroundColor = Color.FromHex("#454645"),
  209. WidthRequest = 5,
  210. HeightRequest = 35,
  211. TextColor = Color.White
  212. };
  213.  
  214. Button buttonSavedDrawings = new Button
  215. {
  216. Text = "Saved Drawings",
  217. FontSize = 8,
  218. BackgroundColor = Color.FromHex("#454645"),
  219. WidthRequest = 5,
  220. HeightRequest = 35,
  221. TextColor = Color.White
  222. };
  223.  
  224. Button buttonSettings = new Button
  225. {
  226. Text = "Settings",
  227. FontSize = 8,
  228. BackgroundColor = Color.FromHex("#454645"),
  229. WidthRequest = 5,
  230. HeightRequest = 35,
  231. TextColor = Color.White
  232. };
  233.  
  234. Button buttonInstructions = new Button
  235. {
  236. Text = "Instructions",
  237. FontSize = 8,
  238. BackgroundColor = Color.FromHex("#454645"),
  239. WidthRequest = 5,
  240. HeightRequest = 35,
  241. TextColor = Color.White
  242. };
  243.  
  244.  
  245. grid.Children.Add(imageBrainLogo, 0, 0);
  246. grid.Children.Add(labelConnectionStatus, 0 , 1);
  247. grid.Children.Add(buttonConnectToSensorBoard, 0, 2);
  248. grid.Children.Add(buttonDrawingMode, 0, 3);
  249. grid.Children.Add(buttonZoneMode, 0, 4);
  250. grid.Children.Add(buttonSavedDrawings, 0, 5);
  251. grid.Children.Add(buttonSettings, 0, 6);
  252. grid.Children.Add(buttonInstructions, 0, 7);
  253.  
  254. view.Children.Add(grid);
  255.  
  256.  
  257.  
  258. /*
  259. view.Children.Add(buttonConnectToSensorBoard);
  260.  
  261. view.Children.Add(buttonDrawingMode);
  262. view.Children.Add(buttonZoneMode);
  263.  
  264. view.Children.Add(buttonSavedDrawings);
  265.  
  266. view.Children.Add(buttonSettings);
  267.  
  268. view.Children.Add(buttonInstructions);
  269.  
  270. */
  271. return view;
  272. }
  273.  
  274. private void ButtonConnectToSensorBoard_Clicked(object sender, EventArgs e)
  275. {
  276. this.Content = CreateBluetoothTemplate();
  277.  
  278. }
  279. }
  280.  
  281.  
  282. public class OnboardingTemplateView : StackLayout
  283. {
  284. public BoxView BackGroundProperty;
  285.  
  286.  
  287. public OnboardingTemplateView()
  288. {
  289. BackGroundProperty = new BoxView
  290. {
  291. HorizontalOptions = LayoutOptions.Fill,
  292. VerticalOptions = LayoutOptions.Fill
  293. };
  294.  
  295.  
  296.  
  297.  
  298.  
  299. Children.Add(BackGroundProperty);
  300. }
  301. }
  302.  
  303. public class OnboardingModel
  304. {
  305. public Color Color { get; set; }
  306. public String ImageSource { get; set; }
  307.  
  308. }
  309.  
  310. public class OnboardingPageVm : INotifyPropertyChanged
  311. {
  312. public event PropertyChangedEventHandler PropertyChanged;
  313. public ObservableCollection<OnboardingModel> BoardingObjectsList { get; set; }
  314.  
  315.  
  316. public OnboardingPageVm()
  317. {
  318. BoardingObjectsList = new ObservableCollection<OnboardingModel>
  319. {
  320. new OnboardingModel
  321. {
  322. Color = Color.FromHex("#292929"),
  323. ImageSource = "ThoughtCastRewrite.walkthroughPage1Element.png"
  324. },
  325. new OnboardingModel
  326. {
  327. Color = Color.FromHex("#292929"),
  328. ImageSource = "ThoughtCastRewrite.walkthroughPage1Element.png"
  329. },
  330. new OnboardingModel
  331. {
  332. Color = Color.FromHex("#292929"),
  333. ImageSource = "ThoughtCastRewrite.walkthroughPage1Element.png"
  334. },
  335. new OnboardingModel
  336. {
  337. Color = Color.FromHex("#292929"),
  338. ImageSource = "ThoughtCastRewrite.walkthroughPage1Element.png"
  339. }
  340. };
  341. }
  342.  
  343. protected virtual void OnPropertyChanged(string propertyName)
  344. {
  345. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  346. }
  347. }
  348.  
  349.  
  350.  
  351.  
  352. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement