db769557190264047e86bd174f797d0bd1558e76
[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 Tizen.Xamarin.Forms.Extension;
19 using TVMediaHub.Tizen.Utils;
20 using TVMediaHub.Tizen.ViewModels;
21 using Xamarin.Forms;
22
23 namespace TVMediaHub.Tizen.Views
24 {
25     /// <summary>
26     /// A custom ContentPage for displaying the music player
27     /// </summary>
28     public partial class MusicPlayer : RelativeLayout
29     {
30         private bool IsInitailized;
31         private Rectangle ShadowImageFocusedBounds;
32         private Rectangle ShadowImageNormalBounds;
33
34         private Rectangle AlbumImageFocusedBounds;
35         private Rectangle AlbumImageNormalBounds;
36
37         private Rectangle PausePlayButtonBounds;
38
39         private Rectangle TitleBounds;
40         private Rectangle ArtistBounds;
41         private Rectangle AlbumNameBounds;
42
43         /// <summary>
44         /// Gets FocusArea for focus chain
45         /// </summary>
46         public Button GetFocusArea()
47         {
48             return MusicPlayerFocusArea;
49         }
50
51         /// <summary>
52         /// A constructor
53         /// </summary>
54         public MusicPlayer()
55         {
56             BindingContext = MusicPlayerViewModelLocator.ViewModel;
57             IsInitailized = false;
58             InitializeComponent();
59             InitializeSize();
60         }
61
62         private void MusicPlayerFocusAreaFocused(object sender, FocusEventArgs e)
63         {
64             MusicPlayerShadowImage.LayoutTo(ShadowImageFocusedBounds);
65             MusicPlayerAlbumArt.LayoutTo(AlbumImageFocusedBounds);
66         }
67
68         private void MusicPlayerFocusAreaUnfocused(object sender, FocusEventArgs e)
69         {
70             MusicPlayerShadowImage.LayoutTo(ShadowImageNormalBounds);
71             MusicPlayerAlbumArt.LayoutTo(AlbumImageNormalBounds);
72         }
73
74         private void InitializeSize()
75         {
76             WidthRequest = SizeUtils.GetWidthSize(546);
77             HeightRequest = SizeUtils.GetHeightSize(546);
78             Margin = new Thickness(SizeUtils.GetWidthSize(-14), SizeUtils.GetHeightSize(-14), 0, 0);
79
80
81             MusicPlayerShadowImage.BorderTop = SizeUtils.GetHeightSize(67);
82             MusicPlayerShadowImage.BorderBottom = SizeUtils.GetHeightSize(67);
83             MusicPlayerShadowImage.BorderLeft = SizeUtils.GetWidthSize(67);
84             MusicPlayerShadowImage.BorderRight = SizeUtils.GetWidthSize(67);
85
86             ShadowImageFocusedBounds = new Rectangle(0, 0, SizeUtils.GetWidthSize(546), SizeUtils.GetHeightSize(546));
87             ShadowImageNormalBounds = new Rectangle(SizeUtils.GetWidthSize(6), SizeUtils.GetHeightSize(6), SizeUtils.GetWidthSize(532), SizeUtils.GetHeightSize(532));
88
89             AlbumImageFocusedBounds = new Rectangle(SizeUtils.GetWidthSize(64), SizeUtils.GetHeightSize(64), SizeUtils.GetWidthSize(418), SizeUtils.GetHeightSize(418));
90             AlbumImageNormalBounds = new Rectangle(SizeUtils.GetWidthSize(70), SizeUtils.GetHeightSize(70), SizeUtils.GetWidthSize(406), SizeUtils.GetHeightSize(406));
91
92             PausePlayButtonBounds = new Rectangle(SizeUtils.GetWidthSize(223), SizeUtils.GetHeightSize(223), SizeUtils.GetWidthSize(100), SizeUtils.GetHeightSize(100));
93
94             TitleBounds = new Rectangle(SizeUtils.GetWidthSize(72), SizeUtils.GetHeightSize(498), SizeUtils.GetWidthSize(406), SizeUtils.GetHeightSize(32));
95             ArtistBounds = new Rectangle(SizeUtils.GetWidthSize(72), SizeUtils.GetHeightSize(542), SizeUtils.GetWidthSize(418), SizeUtils.GetHeightSize(28));
96             AlbumNameBounds = new Rectangle(SizeUtils.GetWidthSize(72), SizeUtils.GetHeightSize(572), SizeUtils.GetWidthSize(418), SizeUtils.GetHeightSize(28));
97
98             MusicPlayerTitle.FontSize = SizeUtils.GetFontSize(28);
99
100             MusicPlayerArtist.FontSize = SizeUtils.GetFontSize(24);
101             MusicPlayerArtist.Opacity = 0.5;
102
103             MusicPlayerAlbum.FontSize = SizeUtils.GetFontSize(24);
104             MusicPlayerAlbum.Opacity = 0.25;
105         }
106
107         protected override void LayoutChildren(double x, double y, double width, double height)
108         {
109             if (IsInitailized == false)
110             {
111                 base.LayoutChildren(x, y, width, height);
112                 MusicPlayerAlbumArt.Layout(AlbumImageNormalBounds);
113                 MusicPlayerTitle.Layout(TitleBounds);
114                 MusicPlayerArtist.Layout(ArtistBounds);
115                 MusicPlayerAlbum.Layout(AlbumNameBounds);
116                 MusicPlayerShadowImage.Layout(ShadowImageNormalBounds);
117                 MusicPlayerPausePlayButton.Layout(PausePlayButtonBounds);
118                 MusicPlayerFocusArea.Layout(PausePlayButtonBounds);
119                 IsInitailized = true;
120             }
121         }
122     }
123 }