Fixed N_SE-38563, N_SE-38552
[apps/osp/Settings.git] / src / StAboutPhoneForm.cpp
1 //
2 // Copyright (c) 2012 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 /**
18  * @file                StAboutPhoneForm.cpp
19  * @brief               This is the implementation file for PhoneInfoForm class.
20  */
21
22 #include <FTelephony.h>
23 #include "StAboutPhoneForm.h"
24 #include "StBluetoothPresentationModel.h"
25 #include "StResourceManager.h"
26 #include "StSettingScenesList.h"
27 #include "StTypes.h"
28 #include "StWifiPresentationModel.h"
29
30 using namespace Tizen::App;
31 using namespace Tizen::Base;
32 using namespace Tizen::Graphics;
33 using namespace Tizen::Net::Wifi;
34 using namespace Tizen::System;
35 using namespace Tizen::Telephony;
36 using namespace Tizen::Ui;
37 using namespace Tizen::Ui::Controls;
38 using namespace Tizen::Ui::Scenes;
39
40 static const int ID_GROUP_ABOUT_PHONE_MAIN = 0;
41 static const int ID_GROUP_ABOUT_PHONE_MAIN_ITEM_COUNT = 8;
42 static const int ID_ITEM_ABOUT_PHONE_MAIN_NAME = 0;
43 static const int ID_ITEM_ABOUT_PHONE_MAIN_MY_NUMBER = 1;
44 static const int ID_ITEM_ABOUT_PHONE_MAIN_MODEL = 2;
45 static const int ID_ITEM_ABOUT_PHONE_MAIN_VERSION = 3;
46 static const int ID_ITEM_ABOUT_PHONE_MAIN_BLUETOOTH = 4;
47 static const int ID_ITEM_ABOUT_PHONE_MAIN_WIFI = 5;
48 static const int ID_ITEM_ABOUT_PHONE_MAIN_BATTERY = 6;
49 static const int ID_ITEM_ABOUT_PHONE_MAIN_CPU_USAGE = 7;
50
51 static const int ID_GROUP_ABOUT_PHONE_CERTIFICATE = 1;
52 static const int ID_GROUP_ABOUT_PHONE_CERTIFICATE_ITEM_COUNT = 1;
53
54 static const int ID_GROUP_COUNT = 2;
55 static const int ID_GROUP_MAX_ITEM_COUNT = ID_GROUP_ABOUT_PHONE_MAIN_ITEM_COUNT;
56 static const int LIMIT_EDITFIELD = 100;
57 static const int DEFAULT_TEXT_SIZE = 10;
58
59 static const int ID_SECOND_CONTROL = 1;
60 static const int ID_RECEIVED_USER_EVENT_CPU_USAGE = 400;
61
62 static const char ISSPACE = 0x20;
63
64 void
65 CpuUsageGetIntAsyncResultListener::OnResultReceivedForGetValueAsync(int value, result r)
66 {
67         SendEvent(r, value);
68 }
69
70 void
71 CpuUsageGetIntAsyncResultListener::SetSendEventForm(Tizen::Ui::Controls::Form* pForm, int requestId)
72 {
73         __pReceivedForm = pForm;
74         __requestId = requestId;
75 }
76
77 void
78 CpuUsageGetIntAsyncResultListener::SendEvent(result r, int value)
79 {
80         Collection::ArrayList* pData = new (std::nothrow) Collection::ArrayList(Collection::SingleObjectDeleter);
81         pData->Construct();
82
83         pData->Add(new (std::nothrow) String(GetErrorMessage(r)));
84         pData->Add(new (std::nothrow) String(Integer::ToString(value)));
85
86         __pReceivedForm->SendUserEvent( __requestId, pData);
87 }
88
89 PhoneInfoForm::PhoneInfoForm(void)
90         : __pEditField(null)
91         , __CpuUsageGetInfoResultListener(null)
92         , __pCpuUsageData(L"")
93 {
94 }
95
96 PhoneInfoForm::~PhoneInfoForm(void)
97 {
98 }
99
100 void
101 PhoneInfoForm::CreateFooter(void)
102 {
103         Footer* pFooter = GetFooter();
104         AppAssert(pFooter);
105
106         pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
107         pFooter->SetBackButton();
108
109         SetFormBackEventListener(this);
110 }
111
112 result
113 PhoneInfoForm::OnInitializing(void)
114 {
115         CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_ABOUT_PHONE"));
116         CreateFooter();
117         CreateTableView();
118
119         PowerManager::SetBatteryEventListener(this);
120         PowerManager::AddChargingEventListener(*this);
121
122         __pTableView->Draw(true);
123         RefreshTableViewItem(0);
124
125         return E_SUCCESS;
126 }
127
128 result
129 PhoneInfoForm::OnTerminating(void)
130 {
131         if (__pTableView != null)
132         {
133                 __pTableView->SetItemProvider(null);
134         }
135
136         PowerManager::SetBatteryEventListener(null);
137         PowerManager::RemoveChargingEventListener(*this);
138
139         SetFormBackEventListener(null);
140         return E_SUCCESS;
141 }
142
143 void
144 PhoneInfoForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
145 {
146         if (previousSceneId.Equals(IDSCN_CERTIFICATE, false))
147         {
148                 return;
149         }
150 }
151
152 void
153 PhoneInfoForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
154 {
155 }
156
157 void
158 PhoneInfoForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
159 {
160         if (__pEditField == null)
161         {
162                 return;
163         }
164
165         if (__pEditField->GetText().IsEmpty() == true)
166         {
167                 ShowMessageBox(L"", ResourceManager::GetString(L"IDS_ST_BODY_THE_NAME_FIELD_CANNOT_BE_EMPTY"));
168                 __pEditField->SetFocus();
169         }
170         else
171         {
172                 bool showEmptyMessageBox = true;
173                 int textLength = __pEditField->GetText().GetLength();
174
175                 for (int i = 0; i < textLength; i++)
176                 {
177                         wchar_t element;
178                         __pEditField->GetText().GetCharAt(i, element);
179
180                         if (element != ISSPACE)
181                         {
182                                 showEmptyMessageBox = false;
183                                 break;
184                         }
185                 }
186
187                 if (showEmptyMessageBox == true)
188                 {
189                         ShowMessageBox(L"", L"The Name cannot be empty or composited by spaces");
190                         __pEditField->SetFocus();
191                 }
192                 else
193                 {
194                         if (SettingInfo::SetValue(SETTING_INFO_KEY_DEVICE_NAME, __pEditField->GetText()) == E_SUCCESS)
195                         {
196                                 SceneManager* pSceneManager = SceneManager::GetInstance();
197                                 AppAssert(pSceneManager);
198
199                                 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
200                         }
201                 }
202         }
203 }
204
205 int
206 PhoneInfoForm::GetGroupCount(void)
207 {
208         AppLogDebug("ENTER");
209         return ID_GROUP_COUNT;
210 }
211
212 int
213 PhoneInfoForm::GetItemCount(int groupIndex)
214 {
215         int itemCount = 0;
216
217         switch (groupIndex)
218         {
219         case ID_GROUP_ABOUT_PHONE_MAIN:
220                 {
221                         itemCount = ID_GROUP_MAX_ITEM_COUNT;
222                 }
223                 break;
224
225         case ID_GROUP_ABOUT_PHONE_CERTIFICATE:
226                 {
227                         itemCount = ID_GROUP_ABOUT_PHONE_CERTIFICATE_ITEM_COUNT;
228                 }
229                 break;
230
231         default:
232                 break;
233         }
234         AppLogDebug("GetItemCount %d", itemCount);
235
236         return itemCount;
237 }
238
239 TableViewGroupItem*
240 PhoneInfoForm::CreateGroupItem(int groupIndex, int itemWidth)
241 {
242         AppLogDebug("ENTER");
243
244         int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
245         int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
246         LabelTextStyle style = LABEL_TEXT_STYLE_BOLD;
247         String groupText;
248         Label* pLabel = null;
249
250         switch (groupIndex)
251         {
252         case ID_GROUP_ABOUT_PHONE_MAIN:
253                 {
254                         yItemOffset = H_GROUP_INDEX_TITLE_TEXT;
255                         itemHeight = H_GROUP_INDEX_DEFAULT;
256                         groupText = ResourceManager::GetString(L"IDS_ST_BODY_DEVICE_INFO");
257                 }
258                 break;
259
260         default:
261                 {
262                         yItemOffset = Y_GROUP_INDEX_DEFAULT;
263                         itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
264                 }
265                 break;
266         }
267
268         Rectangle itemMainRectangle(X_GROUP_INDEX_DEFAULT_LABEL, yItemOffset, itemWidth, itemHeight);
269
270         RelativeLayout relativeLayout;
271         relativeLayout.Construct();
272
273         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
274         pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
275         pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
276
277         pLabel = new (std::nothrow) Label();
278         pLabel->Construct(itemMainRectangle, groupText);
279         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
280         pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
281         pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
282         pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
283
284         pItem->AddControl(pLabel);
285         pItem->SetEnabled(false);
286         relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
287         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
288         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
289
290         return pItem;
291 }
292
293 TableViewItem*
294 PhoneInfoForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
295 {
296         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
297
298         String batteryText;
299         bool isItemSubText = false;
300         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
301         Rectangle itemMainRectangle;
302         Rectangle itemSubRectangle;
303         String itemMainText;
304         String itemSubText;
305         Label* pLabel = null;
306         int itemHeight = H_GROUP_ITEM_DEFAULT;
307         int fontSize = GetFontSize();
308
309         if (groupIndex == ID_GROUP_ABOUT_PHONE_MAIN)
310         {
311                 isItemSubText = true;
312                 ItemTypeTwoLine(itemMainRectangle, itemSubRectangle, fontSize);
313                 itemHeight = (itemMainRectangle.height + itemSubRectangle.height);
314
315                 switch (itemIndex)
316                 {
317                 case ID_ITEM_ABOUT_PHONE_MAIN_NAME:
318                         {
319                                 itemMainRectangle.x = 0;
320                                 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_NAME");
321
322                                 String phoneName;
323                                 if (SettingInfo::GetValue(SETTING_INFO_KEY_DEVICE_NAME, phoneName) != E_SUCCESS)
324                                 {
325                                         itemSubText = L"Tizen";
326                                 }
327                                 else
328                                 {
329                                         itemSubText.Append(phoneName);
330                                 }
331                                 ItemTypeOneLine(itemMainRectangle);
332                                 itemMainRectangle.height = itemHeight;
333                                 isItemSubText = false;
334                         }
335                         break;
336
337                 case ID_ITEM_ABOUT_PHONE_MAIN_MY_NUMBER:
338                         {
339                                 SimStateManager* pSimStateManager = new (std::nothrow) SimStateManager();
340                                 SimInfo simInfo;
341
342                                 if (pSimStateManager->Construct() == E_SUCCESS && pSimStateManager->GetSimInfo(simInfo) == E_SUCCESS)
343                                 {
344                                         itemSubText = simInfo.GetPhoneNumber();
345
346                                         if (itemSubText.IsEmpty() == true)
347                                         {
348                                                 itemSubText = ResourceManager::GetString(L"IDS_ST_HEADER_UNAVAILABLE");
349                                         }
350                                 }
351                                 else
352                                 {
353                                         itemSubText = ResourceManager::GetString(L"IDS_ST_HEADER_UNAVAILABLE");
354                                 }
355
356                                 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_MY_NUMBER");
357                                 delete pSimStateManager;
358                         }
359                         break;
360
361                 case ID_ITEM_ABOUT_PHONE_MAIN_MODEL:
362                         {
363                                 if (SystemInfo::GetValue(SYSTEM_INFO_KEY_MODELNAME, itemSubText) != E_SUCCESS)
364                                 {
365                                         itemSubText = ResourceManager::GetString(L"IDS_ST_HEADER_UNAVAILABLE");
366                                         AppLogDebug("GetValue Fail.. - %s", GetErrorMessage(GetLastResult()));
367                                 }
368
369                                 itemMainText = ResourceManager::GetString(L"IDS_COM_BODY_MODEL");
370                         }
371                         break;
372
373                 case ID_ITEM_ABOUT_PHONE_MAIN_VERSION:
374                         {
375                                 String getVersion;
376                                 if (SystemInfo::GetPlatformVersion(getVersion) == E_SUCCESS)
377                                 {
378                                         itemSubText.Remove(0, itemSubText.GetLength());
379                                         itemSubText.Insert(getVersion, itemSubText.GetLength());
380                                 }
381                                 else
382                                 {
383                                         itemSubText = ResourceManager::GetString(L"IDS_ST_HEADER_UNAVAILABLE");
384                                 }
385                                 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_VERSION");
386                         }
387                         break;
388
389                 case ID_ITEM_ABOUT_PHONE_MAIN_BLUETOOTH:
390                         {
391                                 bool EnableStatus = false;
392                                 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_BLUETOOTH");
393
394                                 if (SystemInfo::GetValue(SYSTEM_INFO_KEY_BLUETOOTH, EnableStatus) == E_SUCCESS)
395                                 {
396                                         BluetoothPresentationModel* pInstance = BluetoothPresentationModel::GetInstance();
397                                         if (EnableStatus == true && pInstance != null)
398                                         {
399                                                 itemSubText = pInstance->GetBluetoothLocalMacAddress();
400                                         }
401                                 }
402
403                                 if (itemSubText.IsEmpty() == true)
404                                 {
405                                         itemSubText = ResourceManager::GetString(L"IDS_ST_HEADER_UNAVAILABLE");
406                                 }
407                         }
408                         break;
409
410                 case ID_ITEM_ABOUT_PHONE_MAIN_WIFI:
411                         {
412                                 bool EnableStatus = false;
413                                 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_WI_FI");
414
415                                 if (SystemInfo::GetValue(SYSTEM_INFO_KEY_WIFI, EnableStatus) == E_SUCCESS)
416                                 {
417                                         WifiPresentationModel* pInstance = WifiPresentationModel::GetInstance();
418                                         if (EnableStatus == true && pInstance != null)
419                                         {
420                                                 itemSubText = pInstance->GetWifiMacAddress();
421                                         }
422                                 }
423
424                                 if (itemSubText.IsEmpty() == true)
425                                 {
426                                         itemSubText = ResourceManager::GetString(L"IDS_ST_HEADER_UNAVAILABLE");
427                                 }
428                         }
429                         break;
430
431                 case ID_ITEM_ABOUT_PHONE_MAIN_BATTERY:
432                         {
433                                 int batteryLevel = 0;
434
435                                 Battery::GetCurrentLevelInPercentage(batteryLevel);
436                                 batteryText.Format(DEFAULT_TEXT_SIZE, L"%d%%", batteryLevel);
437                                 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_BATTERY");
438                         }
439                         break;
440
441                 case ID_ITEM_ABOUT_PHONE_MAIN_CPU_USAGE:
442                         {
443                                 int cpuUsage = 0;
444                                 SetICpuUsageResultListener();
445
446                                 if (RuntimeInfo::GetValueAsync(RUNTIME_INFO_KEY_CPU_USAGE, __CpuUsageGetInfoResultListener))
447                                 {
448                                         itemSubText = Integer::ToString(cpuUsage);
449                                         itemSubText.Append(L"%");
450                                 }
451                                 else
452                                 {
453                                         AppLogDebug("Get Value Result [%s]", GetErrorMessage(GetLastResult()));
454                                         itemSubText = L"0%";
455                                 }
456
457                                 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_CPU_USAGE");
458                         }
459                         break;
460
461                 default:
462                         break;
463                 }
464         }
465         else
466         {
467                 itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_CERTIFICATES");
468                 ItemTypeOneLine(itemMainRectangle);
469         }
470
471         RelativeLayout relativeLayout;
472         relativeLayout.Construct();
473
474         TableViewItem* pItem = new (std::nothrow) TableViewItem();
475         pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight), style);
476         pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
477
478         if ((groupIndex == ID_GROUP_ABOUT_PHONE_MAIN) && (itemIndex == ID_ITEM_ABOUT_PHONE_MAIN_NAME))
479         {
480                 __pEditField = new (std::nothrow) EditField();
481                 __pEditField->Construct(itemMainRectangle, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY, EDIT_FIELD_TITLE_STYLE_TOP, true, LIMIT_EDITFIELD, GROUP_STYLE_NONE);
482                 __pEditField->SetGuideText(ResourceManager::GetString(L"IDS_ST_HEADER_DEVICE_NAME_ABB"));
483                 __pEditField->SetTitleText(itemMainText);
484                 __pEditField->SetText(itemSubText);
485                 __pEditField->SetTextSize(fontSize);
486                 __pEditField->SetTitleTextColor(EDIT_STATUS_NORMAL, COLOR_HELP_TEXT_TYPE_01);
487                 __pEditField->SetColor(EDIT_STATUS_NORMAL, COLOR_BG_GROUP_INDEX_DEFAULT);
488                 __pEditField->SetColor(EDIT_STATUS_PRESSED, COLOR_BG_GROUP_INDEX_DEFAULT);
489                 __pEditField->SetColor(EDIT_STATUS_HIGHLIGHTED, COLOR_BG_GROUP_INDEX_DEFAULT);
490
491                 __pEditField->AddActionEventListener(*this);
492                 __pEditField->AddKeypadEventListener(*this);
493
494                 pItem->SetIndividualSelectionEnabled(__pEditField, true);
495                 pItem->AddControl(__pEditField);
496
497                 relativeLayout.SetMargin(*__pEditField, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
498                 relativeLayout.SetRelation(*__pEditField, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
499                 relativeLayout.SetRelation(*__pEditField, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
500         }
501         else
502         {
503                 pLabel = new (std::nothrow) Label();
504                 pLabel->Construct(itemMainRectangle, itemMainText);
505                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
506                 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
507                 pLabel->SetTextColor(COLOR_MAIN_TEXT);
508
509                 if (groupIndex != ID_GROUP_ABOUT_PHONE_CERTIFICATE)
510                 {
511                         pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT, TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
512                         pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT, TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
513                         pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT, TABLE_VIEW_ITEM_DRAWING_STATUS_HIGHLIGHTED);
514                 }
515                 pItem->AddControl(pLabel);
516
517                 relativeLayout.SetMargin(*pLabel, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
518                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
519                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
520                 if (isItemSubText == true)
521                 {
522                         if ((groupIndex == ID_GROUP_ABOUT_PHONE_MAIN) && (itemIndex == ID_ITEM_ABOUT_PHONE_MAIN_BATTERY))
523                         {
524                                 itemSubText = batteryText;
525                         }
526                         pLabel = new (std::nothrow) Label();
527                         pLabel->Construct(itemSubRectangle, itemSubText);
528                         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
529                         pLabel->SetTextConfig(FONT_SIZE_SUB_TEXT, LABEL_TEXT_STYLE_NORMAL);
530                         pLabel->SetTextColor(COLOR_SUB_TEXT);
531                         pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT, TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
532                         pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT, TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
533                         pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT, TABLE_VIEW_ITEM_DRAWING_STATUS_HIGHLIGHTED);
534                         pItem->AddControl(pLabel);
535                         relativeLayout.SetMargin(*pLabel, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
536                         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
537                         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
538                 }
539         }
540
541         return pItem;
542 }
543
544 bool
545 PhoneInfoForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
546 {
547         AppLogDebug("ENTER");
548
549         delete pItem;
550         pItem = null;   
551
552         return true;
553 }
554
555 bool
556 PhoneInfoForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
557 {
558         AppLogDebug("ENTER");
559
560         delete pItem;
561         pItem = null;
562
563         return true;
564 }
565
566 void
567 PhoneInfoForm::OnBatteryLevelChangedInPercentage(int percentage)
568 {
569         if (__pTableView != null)
570         {
571                 __pTableView->RefreshItem(ID_GROUP_ABOUT_PHONE_MAIN, ID_ITEM_ABOUT_PHONE_MAIN_BATTERY, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
572         }
573 }
574
575 void
576 PhoneInfoForm::OnChargingStateChanged(bool charging)
577 {
578         AppLogDebug("charging %d", charging);
579 }
580
581 void
582 PhoneInfoForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
583 {
584         if (__pEditField != null)
585         {
586                 __pEditField->HideKeypad();
587                 __pEditField->Invalidate(false);
588         }
589
590         switch (groupIndex)
591         {
592         case ID_GROUP_ABOUT_PHONE_CERTIFICATE:
593                 {
594                         SceneManager* pSceneManager = SceneManager::GetInstance();
595                         AppAssert(pSceneManager);
596
597                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CERTIFICATE, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), null);
598                 }
599                 break;
600
601         default:
602                 {
603                         SetFocus();
604                 }
605                 break;
606         }
607 }
608
609 int
610 PhoneInfoForm::GetDefaultGroupItemHeight(void)
611 {
612         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
613 }
614
615 int
616 PhoneInfoForm::GetDefaultItemHeight(void)
617 {
618         return H_GROUP_ITEM_DEFAULT;
619 }
620
621 void
622 PhoneInfoForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
623 {
624 }
625
626 void
627 PhoneInfoForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
628 {
629         AppLogDebug("update :: group[%d] item[%d]", groupIndex, itemIndex);
630
631         if ( groupIndex == ID_GROUP_ABOUT_PHONE_MAIN)
632         {
633                 Label* pFirstLine;
634                 Label* pSecondLine;
635
636                 switch (itemIndex)
637                 {
638                 case ID_ITEM_ABOUT_PHONE_MAIN_NAME:
639                         {
640                                 EditField* pEditField = static_cast<EditField*>(pItem->GetControl(0));
641                                 if (pEditField == null)
642                                 {
643                                         AppLogDebug("ID_ITEM_ABOUT_PHONE_MAIN_NAME Label is null");
644                                         return;
645                                 }
646
647                                 String phoneName;
648
649                                 if (SettingInfo::GetValue(SETTING_INFO_KEY_DEVICE_NAME, phoneName) == E_SUCCESS)
650                                 {
651                                         if (!pEditField->GetText().Equals(phoneName, false))
652                                         {
653                                                 pEditField->SetText(phoneName);
654                                                 pEditField->Invalidate(false);
655                                         }
656                                 }
657                         }
658                         break;
659
660                 case ID_ITEM_ABOUT_PHONE_MAIN_MY_NUMBER:
661                         {
662                                 pFirstLine = static_cast<Label*>(pItem->GetControl(0));
663                                 pSecondLine = static_cast<Label*>(pItem->GetControl(1));
664                                 if ((pFirstLine == null) || (pSecondLine == null))
665                                 {
666                                         AppLogDebug("ID_ITEM_ABOUT_PHONE_MAIN_MY_NUMBER Label is null");
667                                         return;
668                                 }
669
670                                 String tempValue;
671
672                                 pFirstLine->SetText(ResourceManager::GetString(L"IDS_ST_BODY_MY_NUMBER"));
673                                 pFirstLine->Invalidate(false);
674
675                                 SimStateManager* pSimStateManager = new (std::nothrow) SimStateManager();
676                                 SimInfo simInfo;
677
678                                 if (pSimStateManager->Construct() == E_SUCCESS && pSimStateManager->GetSimInfo(simInfo) == E_SUCCESS)
679                                 {
680                                         tempValue.Remove(0, tempValue.GetLength());
681                                         tempValue = simInfo.GetPhoneNumber();
682
683                                         if (pSecondLine->GetText().Equals(tempValue, false) == false)
684                                         {
685                                                 pSecondLine->Invalidate(false);
686                                         }
687                                 }
688                                 else
689                                 {
690                                         pSecondLine->SetText(ResourceManager::GetString(L"IDS_ST_HEADER_UNAVAILABLE"));
691                                         pSecondLine->Invalidate(false);
692                                 }
693                                 delete pSimStateManager;
694                         }
695                         break;
696
697                 case ID_ITEM_ABOUT_PHONE_MAIN_MODEL:
698                         {
699                                 pFirstLine = static_cast<Label*>(pItem->GetControl(0));
700                                 pSecondLine = static_cast<Label*>(pItem->GetControl(1));
701                                 if ((pFirstLine == null) || (pSecondLine == null))
702                                 {
703                                         AppLogDebug("ID_ITEM_ABOUT_PHONE_MAIN_MODEL Label is null");
704                                         return;
705                                 }
706
707                                 pFirstLine->SetText(ResourceManager::GetString(L"IDS_COM_BODY_MODEL"));
708                                 pFirstLine->Invalidate(false);
709
710                                 String modelName;
711
712                                 if (SystemInfo::GetValue(SYSTEM_INFO_KEY_MODELNAME, modelName) != E_SUCCESS)
713                                 {
714                                         pSecondLine->SetText(ResourceManager::GetString(L"IDS_ST_HEADER_UNAVAILABLE"));
715                                 }
716                                 else
717                                 {
718                                         pSecondLine->SetText(modelName);
719                                 }
720                                 pSecondLine->Invalidate(false);
721                         }
722                         break;
723
724                 case ID_ITEM_ABOUT_PHONE_MAIN_VERSION:
725                         {
726                                 pFirstLine = static_cast<Label*>(pItem->GetControl(0));
727                                 pSecondLine = static_cast<Label*>(pItem->GetControl(1));
728                                 if ((pFirstLine == null) || (pSecondLine == null))
729                                 {
730                                         AppLogDebug("ID_ITEM_ABOUT_PHONE_MAIN_VERSION Label is null");
731                                         return;
732                                 }
733
734                                 pFirstLine->SetText(ResourceManager::GetString(L"IDS_ST_BODY_VERSION"));
735                                 pFirstLine->Invalidate(false);
736
737                                 String phoneVersion;
738                                 if (SystemInfo::GetPlatformVersion(phoneVersion) != E_SUCCESS)
739                                 {
740                                         pSecondLine->SetText(ResourceManager::GetString(L"IDS_ST_HEADER_UNAVAILABLE"));
741                                 }
742                                 else
743                                 {
744                                         pSecondLine->SetText(phoneVersion);
745                                 }
746                                 pSecondLine->Invalidate(false);
747                         }
748                         break;
749
750                 case ID_ITEM_ABOUT_PHONE_MAIN_BLUETOOTH:
751                         {
752                                 bool enableStatus = false;
753
754                                 pFirstLine = static_cast<Label*>(pItem->GetControl(0));
755                                 pSecondLine = static_cast<Label*>(pItem->GetControl(1));
756                                 if ((pFirstLine == null) || (pSecondLine == null))
757                                 {
758                                         AppLogDebug("ID_ITEM_ABOUT_PHONE_MAIN_BLUETOOTH Label is null");
759                                         return;
760                                 }
761
762                                 pFirstLine->SetText(ResourceManager::GetString(L"IDS_ST_BODY_BLUETOOTH"));
763                                 pFirstLine->Invalidate(false);
764
765                                 if (SystemInfo::GetValue(SYSTEM_INFO_KEY_BLUETOOTH, enableStatus) != E_SUCCESS)
766                                 {
767                                         pSecondLine->SetText(ResourceManager::GetString(L"IDS_ST_HEADER_UNAVAILABLE"));
768                                         pSecondLine->Invalidate(false);
769                                 }
770                         }
771                         break;
772
773                 case ID_ITEM_ABOUT_PHONE_MAIN_WIFI:
774                         {
775                                 bool enableStatus = false;
776
777                                 pFirstLine = static_cast<Label*>(pItem->GetControl(0));
778                                 pSecondLine = static_cast<Label*>(pItem->GetControl(1));
779                                 if ((pFirstLine == null) || (pSecondLine == null))
780                                 {
781                                         AppLogDebug("ID_ITEM_ABOUT_PHONE_MAIN_WIFI Label is null");
782                                         return;
783                                 }
784
785                                 pFirstLine->SetText(ResourceManager::GetString(L"IDS_ST_BODY_WI_FI"));
786                                 pFirstLine->Invalidate(false);
787
788                                 if (SystemInfo::GetValue(SYSTEM_INFO_KEY_WIFI, enableStatus) != E_SUCCESS)
789                                 {
790                                         pSecondLine->SetText(ResourceManager::GetString(L"IDS_ST_HEADER_UNAVAILABLE"));
791                                         pSecondLine->Invalidate(false);
792                                 }
793                         }
794                         break;
795
796                 case ID_ITEM_ABOUT_PHONE_MAIN_BATTERY:
797                         {
798                                 int batteryLevel = 0;
799                                 pFirstLine = static_cast<Label*>(pItem->GetControl(0));
800                                 pSecondLine = static_cast<Label*>(pItem->GetControl(ID_SECOND_CONTROL));
801                                 if ((pFirstLine == null) || (pSecondLine == null))
802                                 {
803                                         return;
804                                 }
805
806                                 pFirstLine->SetText(ResourceManager::GetString(L"IDS_ST_BODY_BATTERY"));
807                                 pFirstLine->Invalidate(false);
808
809                                 String batteryPercentage;
810
811                                 Battery::GetCurrentLevelInPercentage(batteryLevel);
812                                 batteryPercentage.Format(DEFAULT_TEXT_SIZE, L"%d%%", batteryLevel);
813
814                                 pSecondLine->SetText(batteryPercentage);
815                                 pSecondLine->Invalidate(false);
816                         }
817                         break;
818
819                 case ID_ITEM_ABOUT_PHONE_MAIN_CPU_USAGE:
820                         {
821                                 Label* pLabel = static_cast<Label*>(pItem->GetControl(ID_SECOND_CONTROL));
822                                 pLabel->SetText(__pCpuUsageData + L"%");
823                                 pLabel->Invalidate(false);
824                         }
825                         break;
826
827                 default:
828                         break;
829                 }
830         }
831 }
832
833 void
834 PhoneInfoForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
835 {
836 }
837
838 void
839 PhoneInfoForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
840 {
841 }
842
843 void
844 PhoneInfoForm::OnKeypadClosed(Tizen::Ui::Control& source)
845 {
846 }
847
848 void
849 PhoneInfoForm::OnKeypadActionPerformed(Tizen::Ui::Control& source, Tizen::Ui::KeypadAction keypadAction)
850 {
851         AppLogDebug("keypadAction Status[%d]", keypadAction);
852
853         switch (keypadAction)
854         {
855         case KEYPAD_ACTION_ENTER:
856                 // fall through
857         case KEYPAD_ACTION_DONE:
858                 {
859                         __pEditField->HideKeypad();
860                         __pEditField->Invalidate(false);
861                 }
862                 break;
863
864         default:
865                 break;
866         }
867 }
868
869 void
870 PhoneInfoForm::SetICpuUsageResultListener(void)
871 {
872         __CpuUsageGetInfoResultListener = new (std::nothrow) CpuUsageGetIntAsyncResultListener();
873         __CpuUsageGetInfoResultListener->SetSendEventForm(this, ID_RECEIVED_USER_EVENT_CPU_USAGE);
874 }
875
876 void
877 PhoneInfoForm::RefreshTableViewItem(int groupIndex)
878 {
879         int itemCount = __pTableView->GetItemCountAt(groupIndex);
880
881         bool showEmptyMessageBox = true;
882         int textLength = __pEditField->GetText().GetLength();
883
884         for (int i = 0; i < textLength; i++)
885         {
886                 wchar_t element;
887                 __pEditField->GetText().GetCharAt(i, element);
888
889                 if (element != ISSPACE)
890                 {
891                         showEmptyMessageBox = false;
892                         break;
893                 }
894         }
895
896         for (int count = 0; count < itemCount; count++)
897         {
898                 if (count == 0)
899                 {
900                         if ((showEmptyMessageBox == true) || (__pEditField->GetText().Equals(L"", false)))
901                         {
902                                 AppLogDebug("__pEditField is empty");
903                         }
904                         else
905                         {
906                                 __pTableView->RefreshItem(groupIndex, count, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
907                         }
908                 }
909                 else
910                 {
911                         __pTableView->RefreshItem(groupIndex, count, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
912                 }
913         }
914 }
915
916 void
917 PhoneInfoForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
918 {
919         AppLogDebug("RequestFrom[%d]", requestId);
920
921         if (requestId == FRFRESH_REQUEST_EVENT)
922         {
923                 RefreshTableViewItem(0);
924         }
925         else if (requestId == BACK_GROUND_EVENT)
926         {
927                 String phoneName;
928                 if (SettingInfo::GetValue(SETTING_INFO_KEY_DEVICE_NAME, phoneName) != E_SUCCESS)
929                 {
930                         AppLogDebug("GetValue Fail ");
931                 }
932                 else
933                 {
934                         if (__pEditField->GetText().IsEmpty() == false)
935                         {
936                                 bool showEmptyMessageBox = true;
937                                 int textLength = __pEditField->GetText().GetLength();
938
939                                 for (int i = 0; i < textLength; i++)
940                                 {
941                                         wchar_t element;
942                                         __pEditField->GetText().GetCharAt(i, element);
943
944                                         if (element != ISSPACE)
945                                         {
946                                                 showEmptyMessageBox = false;
947                                                 break;
948                                         }
949                                 }
950
951                                 if (showEmptyMessageBox == false)
952                                 {
953                                         if (__pEditField->GetText().CompareTo(phoneName))
954                                         {
955                                                 SettingInfo::SetValue(SETTING_INFO_KEY_DEVICE_NAME, __pEditField->GetText());
956                                         }
957                                 }
958                         }
959                 }
960         }
961         if (pArgs == null)
962         {
963                 AppLogDebug("pArgs is null");
964                 return;
965         }
966         if (requestId == ID_RECEIVED_USER_EVENT_CPU_USAGE)
967         {
968                 String* pResult = static_cast<String*>(pArgs->GetAt(0));
969
970                 if (pResult->Equals(L"E_SUCCESS", false))
971                 {
972                         __pCpuUsageData = *(static_cast<String*>(pArgs->GetAt(1)));
973                         __pTableView->RefreshItem(ID_GROUP_ABOUT_PHONE_MAIN, ID_ITEM_ABOUT_PHONE_MAIN_CPU_USAGE, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
974                 }
975                 delete pArgs;
976         }
977 }