Removing Tizen.Xamarin.Forms.Extensions
[profile/tv/apps/dotnet/mediahub.git] / TVMediaHub / TVMediaHub.Tizen / Views / MusicPlayer.xaml.cs
1 /*
2 * Copyright (c) 2017 Samsung Electronics Co., Ltd
3 *
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://floralicense.org/license/
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 using System;
18 using TVMediaHub.Tizen.Utils;
19 using TVMediaHub.Tizen.ViewModels;
20 using Xamarin.Forms;
21
22 namespace TVMediaHub.Tizen.Views
23 {
24     /// <summary>
25     /// A custom ContentPage for displaying the music player
26     /// </summary>
27     public partial class MusicPlayer : RelativeLayout
28     {
29         private bool IsInitailized;
30         private Rectangle ShadowImageFocusedBounds;
31         private Rectangle ShadowImageNormalBounds;
32
33         private Rectangle AlbumImageFocusedBounds;
34         private Rectangle AlbumImageNormalBounds;
35
36         private Rectangle PausePlayButtonBounds;
37
38         private Rectangle TitleBounds;
39         private Rectangle ArtistBounds;
40         private Rectangle AlbumNameBounds;
41
42         /// <summary>
43         /// Gets FocusArea for focus chain
44         /// </summary>
45         public Button GetFocusArea()
46         {
47             return MusicPlayerFocusArea;
48         }
49
50         /// <summary>
51         /// A constructor
52         /// </summary>
53         public MusicPlayer()
54         {
55             BindingContext = MusicPlayerViewModelLocator.ViewModel;
56             IsInitailized = false;
57             InitializeComponent();
58             InitializeSize();
59         }
60
61         private void MusicPlayerFocusAreaFocused(object sender, FocusEventArgs e)
62         {
63             MusicPlayerShadowImage.LayoutTo(ShadowImageFocusedBounds);
64             MusicPlayerAlbumArt.LayoutTo(AlbumImageFocusedBounds);
65         }
66
67         private void MusicPlayerFocusAreaUnfocused(object sender, FocusEventArgs e)
68         {
69             MusicPlayerShadowImage.LayoutTo(ShadowImageNormalBounds);
70             MusicPlayerAlbumArt.LayoutTo(AlbumImageNormalBounds);
71         }
72
73         private void InitializeSize()
74         {
75             WidthRequest = SizeUtils.GetWidthSize(546);
76             HeightRequest = SizeUtils.GetHeightSize(546);
77             Margin = new Thickness(SizeUtils.GetWidthSize(-14), SizeUtils.GetHeightSize(-14), 0, 0);
78
79
80             MusicPlayerShadowImage.BorderTop = SizeUtils.GetHeightSize(67);
81             MusicPlayerShadowImage.BorderBottom = SizeUtils.GetHeightSize(67);
82             MusicPlayerShadowImage.BorderLeft = SizeUtils.GetWidthSize(67);
83             MusicPlayerShadowImage.BorderRight = SizeUtils.GetWidthSize(67);
84
85             ShadowImageFocusedBounds = new Rectangle(0, 0, SizeUtils.GetWidthSize(546), SizeUtils.GetHeightSize(546));
86             ShadowImageNormalBounds = new Rectangle(SizeUtils.GetWidthSize(6), SizeUtils.GetHeightSize(6), SizeUtils.GetWidthSize(532), SizeUtils.GetHeightSize(532));
87
88             AlbumImageFocusedBounds = new Rectangle(SizeUtils.GetWidthSize(64), SizeUtils.GetHeightSize(64), SizeUtils.GetWidthSize(418), SizeUtils.GetHeightSize(418));
89             AlbumImageNormalBounds = new Rectangle(SizeUtils.GetWidthSize(70), SizeUtils.GetHeightSize(70), SizeUtils.GetWidthSize(406), SizeUtils.GetHeightSize(406));
90
91             PausePlayButtonBounds = new Rectangle(SizeUtils.GetWidthSize(223), SizeUtils.GetHeightSize(223), SizeUtils.GetWidthSize(100), SizeUtils.GetHeightSize(100));
92
93             TitleBounds = new Rectangle(SizeUtils.GetWidthSize(72), SizeUtils.GetHeightSize(498), SizeUtils.GetWidthSize(406), SizeUtils.GetHeightSize(32));
94             ArtistBounds = new Rectangle(SizeUtils.GetWidthSize(72), SizeUtils.GetHeightSize(542), SizeUtils.GetWidthSize(418), SizeUtils.GetHeightSize(28));
95             AlbumNameBounds = new Rectangle(SizeUtils.GetWidthSize(72), SizeUtils.GetHeightSize(572), SizeUtils.GetWidthSize(418), SizeUtils.GetHeightSize(28));
96
97             MusicPlayerTitle.FontSize = SizeUtils.GetFontSize(28);
98
99             MusicPlayerArtist.FontSize = SizeUtils.GetFontSize(24);
100             MusicPlayerArtist.Opacity = 0.5;
101
102             MusicPlayerAlbum.FontSize = SizeUtils.GetFontSize(24);
103             MusicPlayerAlbum.Opacity = 0.25;
104         }
105
106         protected override void LayoutChildren(double x, double y, double width, double height)
107         {
108             if (IsInitailized == false)
109             {
110                 base.LayoutChildren(x, y, width, height);
111                 MusicPlayerAlbumArt.Layout(AlbumImageNormalBounds);
112                 MusicPlayerTitle.Layout(TitleBounds);
113                 MusicPlayerArtist.Layout(ArtistBounds);
114                 MusicPlayerAlbum.Layout(AlbumNameBounds);
115                 MusicPlayerShadowImage.Layout(ShadowImageNormalBounds);
116                 MusicPlayerPausePlayButton.Layout(PausePlayButtonBounds);
117                 MusicPlayerFocusArea.Layout(PausePlayButtonBounds);
118                 IsInitailized = true;
119             }
120         }
121     }
122 }