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;
39 static const int ID_GROUP_MAX_ITEM_COUNT = ID_GROUP_BRIGHTNESS_ITEM_COUNT;
41 static const int Y_GROUP_ITEM_SLIDER = -30;
42 static const int GROUP_ITEM_SLIDER_MIN_VALUE = 1;
43 static const int GROUP_ITEM_SLIDER_MAX_VALUE = 10;
45 static const int BRIGHTNESS_DEFAULT_VALUE = 1;
47 BrightnessForm::BrightnessForm(void)
51 BrightnessForm::~BrightnessForm(void)
56 BrightnessForm::CreateFooter(void)
58 Footer* pFooter = GetFooter();
61 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
62 pFooter->SetBackButton();
63 pFooter->AddActionEventListener(*this);
65 SetFormBackEventListener(this);
69 BrightnessForm::OnInitializing(void)
71 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_BRIGHTNESS"));
81 BrightnessForm::OnTerminating(void)
85 SetFormBackEventListener(null);
90 BrightnessForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
92 __pTableView->UpdateTableView();
96 BrightnessForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
101 BrightnessForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
103 SceneManager* pSceneManager = SceneManager::GetInstance();
104 AppAssert(pSceneManager);
106 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
110 BrightnessForm::GetGroupCount(void)
112 AppLogDebug("ENTER");
113 return ID_GROUP_COUNT;
117 BrightnessForm::GetItemCount(int groupIndex)
121 if (groupIndex == ID_GROUP_BRIGHTNESS)
123 itemCount = ID_GROUP_BRIGHTNESS_ITEM_COUNT;
126 AppLogDebug("GetItemCount %d", itemCount);
132 BrightnessForm::CreateGroupItem(int groupIndex, int itemWidth)
134 AppLogDebug("ENTER");
136 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
137 LabelTextStyle style = LABEL_TEXT_STYLE_BOLD;
139 Label* pLabel = null;
141 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
143 RelativeLayout relativeLayout;
144 relativeLayout.Construct();
146 pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_INDEX_NO_TITLE_DEFAULT));
148 pLabel = new (std::nothrow) Label();
149 pLabel->Construct(Rectangle(X_GROUP_INDEX_DEFAULT_LABEL, Y_GROUP_INDEX_DEFAULT_LABEL, itemWidth, itemHeight), groupText);
150 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
151 pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
152 pLabel->SetTextColor(COLOR_GROUP_TITLE_TEXT);
154 pItem->AddControl(pLabel);
155 relativeLayout.SetMargin(*pLabel, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
156 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
157 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
158 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
159 pItem->SetEnabled(false);
165 BrightnessForm::CreateItem(int groupIndex, int itemIndex,int itemWidth)
167 AppLogDebug("CreateItem group[%d] index[%d]", groupIndex, itemIndex);
170 Rectangle itemMainRectangle;
171 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
172 Slider* pSlider = null;
174 Label* pLabel = null;
175 int fontSize = GetFontSize();
177 TableViewItem* pItem = new (std::nothrow) TableViewItem();
178 ItemTypeOneLine(itemMainRectangle);
182 case ID_ITEM_BRIGHTNESS_AUTOMATIC:
184 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_AUTOMATIC");
185 style = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
186 RelativeLayout relativeLayout;
187 relativeLayout.Construct();
189 pItem->Construct(relativeLayout, Dimension(W_GROUP_ITEM_DEFAULT, H_GROUP_ITEM_DEFAULT), style);
190 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
192 pLabel = new (std::nothrow) Label();
193 pLabel->Construct(itemMainRectangle, itemMainText);
194 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
195 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
196 pLabel->SetTextColor(COLOR_MAIN_TEXT);
198 pItem->AddControl(pLabel);
199 relativeLayout.SetMargin(*pLabel, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
200 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
201 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
205 case ID_ITEM_BRIGHTNESS_SLIDE_BAR:
207 itemMainRectangle.width = W_GROUP_ITEM_DEFAULT_SLIDER;
208 itemMainRectangle.height = H_GROUP_ITEM_DEFAULT_SLIDER;
210 RelativeLayout relativeLayout;
211 relativeLayout.Construct();
213 pItem->Construct(relativeLayout, Dimension(W_GROUP_ITEM_DEFAULT, H_GROUP_ITEM_DEFAULT_SLIDER), style);
214 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
216 if ((brightness = PowerManager::GetScreenBrightness()) == 0)
218 brightness = BRIGHTNESS_DEFAULT_VALUE;
221 pSlider = new (std::nothrow) Slider();
222 pSlider->Construct(itemMainRectangle, BACKGROUND_STYLE_NONE, true, GROUP_ITEM_SLIDER_MIN_VALUE, GROUP_ITEM_SLIDER_MAX_VALUE);
223 pSlider->SetValue(brightness);
224 pSlider->SetPosition(itemMainRectangle.x, itemMainRectangle.y + Y_GROUP_ITEM_SLIDER);
225 pSlider->AddAdjustmentEventListener(*this);
226 pSlider->AddSliderEventListener(*this);
228 pItem->AddControl(pSlider);
229 relativeLayout.SetMargin(*pSlider, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
230 relativeLayout.SetRelation(*pSlider, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
231 relativeLayout.SetRelation(*pSlider, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
243 BrightnessForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
245 AppLogDebug("ENTER");
254 BrightnessForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
256 AppLogDebug("ENTER");
265 BrightnessForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
267 AppLogDebug("OnTableViewItemStateChanged group[%d] index[%d]", groupIndex, itemIndex);
272 if (itemIndex == ID_ITEM_BRIGHTNESS_AUTOMATIC)
276 case TABLE_VIEW_ITEM_STATUS_CHECKED:
278 localGroup = ID_GROUP_BRIGHTNESS;
279 localItem = ID_ITEM_BRIGHTNESS_SLIDE_BAR;
281 __pTableView->SetItemEnabled(localGroup, localItem, false);
285 case TABLE_VIEW_ITEM_STATUS_UNCHECKED:
287 localGroup = ID_GROUP_BRIGHTNESS;
288 localItem = ID_ITEM_BRIGHTNESS_SLIDE_BAR;
290 __pTableView->SetItemEnabled(localGroup, localItem, true);
301 BrightnessForm::OnAdjustmentValueChanged(const Tizen::Ui::Control& source, int adjustment)
303 result r = E_SUCCESS;
305 if ((r = PowerManager::SetScreenBrightness(adjustment)) == E_SUCCESS)
307 AppLogDebug("Brightness Set adjustment : %d Level", adjustment);
311 AppLogDebug("Brightness Set allowed from 1 to 10 : adjustment Fail. %d", adjustment);
316 BrightnessForm::OnSliderBarMoved(Tizen::Ui::Controls::Slider& source, int value)
318 result r = E_SUCCESS;
320 if ((r = PowerManager::SetScreenBrightness(value)) == E_SUCCESS)
322 AppLogDebug("Brightness Set value : %d Level ", value);
326 AppLogDebug("Brightness Set allowed from 1 to 10 : Fail : %d", value);
331 BrightnessForm::GetDefaultGroupItemHeight(void)
333 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
337 BrightnessForm::GetDefaultItemHeight(void)
339 return H_GROUP_ITEM_DEFAULT;
343 BrightnessForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
348 BrightnessForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
353 BrightnessForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
358 BrightnessForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)