2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
18 * @file StBrightnessForm.cpp
19 * @brief This is the implementation file for BrightnessForm class.
22 #include "StBrightnessForm.h"
23 #include "StResourceManager.h"
26 using namespace Tizen::Base;
27 using namespace Tizen::Graphics;
28 using namespace Tizen::System;
29 using namespace Tizen::Ui;
30 using namespace Tizen::Ui::Controls;
31 using namespace Tizen::Ui::Scenes;
33 static const int ID_GROUP_BRIGHTNESS = 0;
34 static const int ID_GROUP_BRIGHTNESS_ITEM_COUNT = 2;
35 static const int ID_ITEM_BRIGHTNESS_AUTOMATIC = 0;
36 static const int ID_ITEM_BRIGHTNESS_SLIDE_BAR = 1;
38 static const int ID_GROUP_COUNT = 1;
40 static const int Y_GROUP_ITEM_SLIDER = -30;
41 static const int GROUP_ITEM_SLIDER_MIN_VALUE = 1;
42 static const int GROUP_ITEM_SLIDER_MAX_VALUE = 10;
44 static const int BRIGHTNESS_DEFAULT_VALUE = 1;
46 BrightnessForm::BrightnessForm(void)
50 BrightnessForm::~BrightnessForm(void)
55 BrightnessForm::CreateFooter(void)
57 Footer* pFooter = GetFooter();
60 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
61 pFooter->AddActionEventListener(*this);
63 SetFormBackEventListener(this);
67 BrightnessForm::OnInitializing(void)
69 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_BRIGHTNESS"));
78 BrightnessForm::OnTerminating(void)
82 SetFormBackEventListener(null);
87 BrightnessForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
89 __pTableView->UpdateTableView();
93 BrightnessForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
98 BrightnessForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
100 SceneManager* pSceneManager = SceneManager::GetInstance();
101 AppAssert(pSceneManager);
103 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
107 BrightnessForm::GetGroupCount(void)
109 AppLogDebug("ENTER");
110 return ID_GROUP_COUNT;
114 BrightnessForm::GetItemCount(int groupIndex)
118 if (groupIndex == ID_GROUP_BRIGHTNESS)
120 itemCount = ID_GROUP_BRIGHTNESS_ITEM_COUNT;
123 AppLogDebug("GetItemCount %d", itemCount);
129 BrightnessForm::CreateGroupItem(int groupIndex, int itemWidth)
131 AppLogDebug("ENTER");
133 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
134 LabelTextStyle style = LABEL_TEXT_STYLE_BOLD;
136 Label* pLabel = null;
138 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
140 RelativeLayout relativeLayout;
141 relativeLayout.Construct();
143 pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_INDEX_NO_TITLE_DEFAULT));
145 pLabel = new (std::nothrow) Label();
146 pLabel->Construct(Rectangle(X_GROUP_INDEX_DEFAULT_LABEL, Y_GROUP_INDEX_DEFAULT_LABEL, itemWidth, itemHeight), groupText);
147 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
148 pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
149 pLabel->SetTextColor(COLOR_GROUP_TITLE_TEXT);
151 pItem->AddControl(pLabel);
152 relativeLayout.SetMargin(*pLabel, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
153 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
154 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
155 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
156 pItem->SetEnabled(false);
162 BrightnessForm::CreateItem(int groupIndex, int itemIndex,int itemWidth)
164 AppLogDebug("CreateItem group[%d] index[%d]", groupIndex, itemIndex);
167 Rectangle itemMainRectangle;
168 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
169 Slider* pSlider = null;
171 Label* pLabel = null;
172 int fontSize = GetFontSize();
174 TableViewItem* pItem = new (std::nothrow) TableViewItem();
175 ItemTypeOneLine(itemMainRectangle);
179 case ID_ITEM_BRIGHTNESS_AUTOMATIC:
181 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_AUTOMATIC");
182 style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
183 RelativeLayout relativeLayout;
184 relativeLayout.Construct();
186 pItem->Construct(relativeLayout, Dimension(W_GROUP_ITEM_DEFAULT, H_GROUP_ITEM_DEFAULT), style);
187 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
189 pLabel = new (std::nothrow) Label();
190 pLabel->Construct(itemMainRectangle, itemMainText);
191 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
192 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
193 pLabel->SetTextColor(COLOR_MAIN_TEXT);
195 pItem->AddControl(pLabel);
196 relativeLayout.SetMargin(*pLabel, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
197 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
198 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
202 case ID_ITEM_BRIGHTNESS_SLIDE_BAR:
204 itemMainRectangle.width = W_GROUP_ITEM_DEFAULT_SLIDER;
205 itemMainRectangle.height = H_GROUP_ITEM_DEFAULT_SLIDER;
207 RelativeLayout relativeLayout;
208 relativeLayout.Construct();
210 pItem->Construct(relativeLayout, Dimension(W_GROUP_ITEM_DEFAULT, H_GROUP_ITEM_DEFAULT_SLIDER), style);
211 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
213 if ((brightness = PowerManager::GetScreenBrightness()) == 0)
215 brightness = BRIGHTNESS_DEFAULT_VALUE;
218 pSlider = new (std::nothrow) Slider();
219 pSlider->Construct(itemMainRectangle, BACKGROUND_STYLE_NONE, true, GROUP_ITEM_SLIDER_MIN_VALUE, GROUP_ITEM_SLIDER_MAX_VALUE);
220 pSlider->SetValue(brightness);
221 pSlider->SetPosition(itemMainRectangle.x, itemMainRectangle.y + Y_GROUP_ITEM_SLIDER);
222 pSlider->AddAdjustmentEventListener(*this);
223 pSlider->AddSliderEventListener(*this);
225 pItem->AddControl(pSlider);
226 relativeLayout.SetMargin(*pSlider, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
227 relativeLayout.SetRelation(*pSlider, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
228 relativeLayout.SetRelation(*pSlider, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
240 BrightnessForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
242 AppLogDebug("ENTER");
251 BrightnessForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
253 AppLogDebug("ENTER");
262 BrightnessForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
264 AppLogDebug("OnTableViewItemStateChanged group[%d] index[%d]", groupIndex, itemIndex);
269 if (itemIndex == ID_ITEM_BRIGHTNESS_AUTOMATIC)
273 case TABLE_VIEW_ITEM_STATUS_CHECKED:
275 localGroup = ID_GROUP_BRIGHTNESS;
276 localItem = ID_ITEM_BRIGHTNESS_SLIDE_BAR;
278 __pTableView->SetItemEnabled(localGroup, localItem, false);
282 case TABLE_VIEW_ITEM_STATUS_UNCHECKED:
284 localGroup = ID_GROUP_BRIGHTNESS;
285 localItem = ID_ITEM_BRIGHTNESS_SLIDE_BAR;
287 __pTableView->SetItemEnabled(localGroup, localItem, true);
298 BrightnessForm::OnAdjustmentValueChanged(const Tizen::Ui::Control& source, int adjustment)
300 result r = E_SUCCESS;
302 if ((r = PowerManager::SetScreenBrightness(adjustment)) == E_SUCCESS)
304 AppLogDebug("Brightness Set adjustment : %d Level", adjustment);
308 AppLogDebug("Brightness Set allowed from 1 to 10 : adjustment Fail. %d", adjustment);
313 BrightnessForm::OnSliderBarMoved(Tizen::Ui::Controls::Slider& source, int value)
315 result r = E_SUCCESS;
317 if ((r = PowerManager::SetScreenBrightness(value)) == E_SUCCESS)
319 AppLogDebug("Brightness Set value : %d Level ", value);
323 AppLogDebug("Brightness Set allowed from 1 to 10 : Fail : %d", value);
328 BrightnessForm::GetDefaultGroupItemHeight(void)
330 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
334 BrightnessForm::GetDefaultItemHeight(void)
336 return H_GROUP_ITEM_DEFAULT;
340 BrightnessForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
345 BrightnessForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
350 BrightnessForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
355 BrightnessForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)