3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.1 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 //!Internet IntBrightness class
19 /*@file: IntBrightness.cpp
20 *@brief: This class defines IntBrightness used to change the brightness
25 #include <FAppUiApp.h>
27 #include "IntBrightnessForm.h"
28 #include "IntCommonLib.h"
29 #include "IntMultipleWindowPresentationModel.h"
30 #include "IntSceneRegister.h"
32 using namespace Tizen::App;
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
35 using namespace Tizen::Graphics;
36 using namespace Tizen::System;
37 using namespace Tizen::Ui;
38 using namespace Tizen::Ui::Controls;
39 using namespace Tizen::Ui::Scenes;
41 const int IDA_AUTOBTN_CLICKED = 101;
42 const int IDA_MANUALBTN_CLICKED = 102;
44 BrightnessForm::BrightnessForm(void)
46 __manualBrightness = true;
47 __pBrightnessSlider = null;
51 BrightnessForm::~BrightnessForm(void)
57 BrightnessForm::Initialize()
59 Form::Construct(L"IDL_BRIGHTNESS");
65 BrightnessForm::OnInitializing(void)
68 WindowInfo* pWindowInfo = null;
70 SceneManager* pSceneManager = SceneManager::GetInstance();
71 if (pSceneManager != null)
73 r = pSceneManager->AddSceneEventListener(IDSCN_BRIGHTNESS, *this);
76 AppLogException("OnInitialized failed with %s", GetErrorMessage(r));
80 AddOrientationEventListener(*this);
81 SetFormBackEventListener(this);
83 __pLabel = static_cast< Label* >(GetControl(L"IDC_LABEL", true));
85 pWindowInfo = MultipleWindowPresentationModel::GetInstance()->GetActiveWindowInfo();
86 if (pWindowInfo != null && pWindowInfo->pWebCanvasBitmap != null && __pLabel != null)
88 int labelWidth = __pLabel->GetWidth();
89 int labelHeigth = __pLabel->GetHeight();
91 if(GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
93 labelWidth = pWindowInfo->pWebCanvasBitmap->GetWidth() * labelHeigth / pWindowInfo->pWebCanvasBitmap->GetHeight();
94 __pLabel->SetBounds(__pLabel->GetX() + (__pLabel->GetWidth() - labelWidth)/2, __pLabel->GetY(), labelWidth, labelHeigth);
98 labelHeigth = pWindowInfo->pWebCanvasBitmap->GetHeight() * labelWidth / pWindowInfo->pWebCanvasBitmap->GetWidth();
99 __pLabel->SetBounds(__pLabel->GetX(), __pLabel->GetY() + (__pLabel->GetHeight() - labelHeigth)/2, labelWidth, labelHeigth);
101 __pLabel->SetBackgroundBitmap(*pWindowInfo->pWebCanvasBitmap);
104 AppRegistry* pAppRegistry = App::GetInstance()->GetAppRegistry();
105 String sliderKey("SliderValue");
106 String tabKey("TabButton");
107 int sliderValue = 10;
110 r = pAppRegistry->Get(sliderKey, sliderValue);
111 if (r == E_KEY_NOT_FOUND)
113 pAppRegistry->Add(sliderKey, sliderValue);
114 pAppRegistry->Set(sliderKey,sliderValue);
117 r = pAppRegistry->Get(tabKey, tabValue);
118 if (r == E_KEY_NOT_FOUND)
120 pAppRegistry->Add(tabKey, tabValue);
121 pAppRegistry->Set(tabKey,tabValue);
123 r = pAppRegistry->Save();
126 // Failed to save data to registry
127 AppLogDebug("OnInitialized failed to save data to registry with %s", GetErrorMessage(r));
132 __pBrightnessSlider = static_cast< Slider* >(GetControl(L"IDC_FONT_SLIDER", true));
133 if (__pBrightnessSlider == null)
137 __pBrightnessSlider->SetRange(1,10);
138 __pBrightnessSlider->SetValue(sliderValue);
139 __pBrightnessSlider->AddSliderEventListener(*this);
140 __pBrightnessSlider->AddAdjustmentEventListener(*this);
142 GetFooter()->AddActionEventListener(*this);
147 BrightnessForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
149 result r = E_FAILURE;
150 AppRegistry* pAppRegistry = App::GetInstance()->GetAppRegistry();
151 String sliderKey("SliderValue");
152 String tabKey("TabButton");
153 int sliderValue = 10;
156 r = pAppRegistry->Get(sliderKey, sliderValue);
157 r = pAppRegistry->Get(tabKey, tabValue);
159 AppLog("BrightnessForm tab value is %d",tabValue);
160 AppLog("BrightnessForm slider value is %d",sliderValue);
162 if(__pBrightnessSlider == null)
169 __pBrightnessSlider->SetEnabled(false);
170 __pBrightnessSlider->Invalidate(true);
174 __pBrightnessSlider->SetEnabled(true);
175 AppLog("BatteryLvl %d",PowerManager::GetScreenBrightness());
176 __pBrightnessSlider->SetValue(sliderValue);
177 __pBrightnessSlider->Invalidate(true);
180 GetFooter()->SetItemSelected(tabValue);
182 __pBrightnessSlider->SetRange(1,10);
183 // __pBrightnessSlider->SetValue(sliderValue);
186 AppLog("slider value is %d",PowerManager::GetScreenBrightness());
193 BrightnessForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
195 AppLog("slider value is %d",PowerManager::GetScreenBrightness());
196 __pBrightnessSlider->SetValue(PowerManager::GetScreenBrightness());
201 BrightnessForm::OnSliderBarMoved(Slider& source, int value)
203 AppLog("coming to OnSliderBarMoved");
204 if (__manualBrightness == true)
206 PowerManager::SetScreenBrightness(value);
207 AppRegistry* pAppRegistry = App::GetInstance()->GetAppRegistry();
208 String sliderKey("SliderValue");
211 pAppRegistry->Set(sliderKey,value);
216 BrightnessForm::OnAdjustmentValueChanged(const Tizen::Ui::Control& source, int adjustment)
218 if(source.Equals(*__pBrightnessSlider) == true)
220 AppLog("coming to OnSliderBarMoved");
221 if (__manualBrightness == true)
223 PowerManager::SetScreenBrightness(adjustment);
224 AppRegistry* pAppRegistry = App::GetInstance()->GetAppRegistry();
225 String sliderKey("SliderValue");
228 pAppRegistry->Set(sliderKey,adjustment);
235 BrightnessForm::OnFormBackRequested(Form& source)
238 result r = E_FAILURE;
239 SceneManager* pSceneManager = SceneManager::GetInstance();
240 if (pSceneManager != null)
242 // save the slider value
243 // save the tab button
244 AppRegistry* pAppRegistry = App::GetInstance()->GetAppRegistry();
245 String sliderKey("SliderValue");
246 String tabKey("TabButton");
247 int sliderValue = __pBrightnessSlider->GetValue();
248 r = pAppRegistry->Set(sliderKey,sliderValue);
249 FooterItemStatus footerStatus;
250 GetFooter()->GetItemStatus(0,footerStatus);
251 if (footerStatus == FOOTER_ITEM_STATUS_SELECTED || footerStatus == FOOTER_ITEM_STATUS_HIGHLIGHTED)
253 r = pAppRegistry->Set(tabKey,0);
257 r = pAppRegistry->Set(tabKey,1);
259 pAppRegistry->Save();
260 r = pSceneManager->GoBackward(BackwardSceneTransition());
263 AppLogException("OnFormBackRequested failed with %s", GetErrorMessage(r));
270 BrightnessForm::OnActionPerformed(const Control& source, int actionId)
272 result r = E_SUCCESS;
275 case IDA_AUTOBTN_CLICKED:
276 if(__manualBrightness == false)
280 __manualBrightness = false;
281 __pBrightnessSlider->SetValue(6);
282 // __pBrightnessSlider->SetShowState(false);
283 PowerManager::SetScreenBrightness(6);
284 __pBrightnessSlider->SetEnabled(false);
285 __pBrightnessSlider->Invalidate(true);
287 case IDA_MANUALBTN_CLICKED:
288 PowerManager::SetScreenBrightness(__pBrightnessSlider->GetValue());
289 //__pBrightnessSlider->SetValue(__pBrightnessSlider->GetValue());
290 __pBrightnessSlider->SetEnabled(true);
291 __pBrightnessSlider->SetShowState(true);
292 __pBrightnessSlider->Invalidate(true);
294 __manualBrightness = true;
299 // save the slider value
300 // save the tab button
301 AppRegistry* pAppRegistry = App::GetInstance()->GetAppRegistry();
302 String sliderKey("SliderValue");
303 String tabKey("TabButton");
304 int sliderValue = __pBrightnessSlider->GetValue();
305 r = pAppRegistry->Set(sliderKey,sliderValue);
306 FooterItemStatus footerStatus;
307 GetFooter()->GetItemStatus(0,footerStatus);
308 if (footerStatus == FOOTER_ITEM_STATUS_SELECTED || footerStatus == FOOTER_ITEM_STATUS_HIGHLIGHTED)
310 r = pAppRegistry->Set(tabKey,0);
314 r = pAppRegistry->Set(tabKey,1);
316 pAppRegistry->Save();
320 BrightnessForm::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
322 WindowInfo* pWindowInfo = MultipleWindowPresentationModel::GetInstance()->GetActiveWindowInfo();
324 if (pWindowInfo != null)
326 if(pWindowInfo->pWebCanvasBitmap != null)
328 int labelWidth = __pLabel->GetWidth();
329 int labelHeigth = __pLabel->GetHeight();
331 if(orientationStatus == ORIENTATION_STATUS_LANDSCAPE || orientationStatus == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
333 labelWidth = pWindowInfo->pWebCanvasBitmap->GetWidth() * labelHeigth / pWindowInfo->pWebCanvasBitmap->GetHeight();
334 __pLabel->SetBounds(__pLabel->GetX() + (__pLabel->GetWidth() - labelWidth)/2, __pLabel->GetY(), labelWidth, labelHeigth);
338 labelHeigth = pWindowInfo->pWebCanvasBitmap->GetHeight() * labelWidth / pWindowInfo->pWebCanvasBitmap->GetWidth();
339 __pLabel->SetBounds(__pLabel->GetX(), __pLabel->GetY() + (__pLabel->GetHeight() - labelHeigth)/2, labelWidth, labelHeigth);
347 BrightnessForm::OnUserEventReceivedN (RequestId requestId, Tizen::Base::Collection::IList *pArgs)
349 if (requestId == DEVICE_BRIGHTNESS_CHANGE_EVENT)
351 String key = L"http://tizen.org/setting/screen.brightness" ;
352 int sliderValue = 10;
353 SettingInfo::GetValue(key,sliderValue);
354 if( (sliderValue/10) + 1 > 10)
355 __pBrightnessSlider->SetValue(10);
357 __pBrightnessSlider->SetValue((sliderValue/10) + 1);
358 __pBrightnessSlider->Invalidate(true);