Applied latest source code
[apps/native/preloaded/Clock.git] / src / ClkAlarmEditorForm.cpp
1 //
2 //  Tizen Native SDK
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://floralicense.org/license/
10 //
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.
16 //
17
18 /**
19  * @file        AlarmEditorForm.cpp
20  * @brief       Used to define AlarmEditorForm
21  */
22
23 #include <FApp.h>
24 #include <FAppAppControl.h>
25 #include <FBase.h>
26 #include <FIo.h>
27 #include <FSysDeviceManager.h>
28 #include <FSystem.h>
29 #include <FText.h>
30 #include <FUi.h>
31 #include <FUiInputConnection.h>
32 #include <FUiIInputConnectionEventListener.h>
33
34 #include "ClkAlarm.h"
35 #include "ClkAlarmEditorForm.h"
36 #include "ClkAlarmPresentationModel.h"
37 #include "ClkAlarmRepeatCustomItem.h"
38 #include "ClkCheckBoxCustomItem.h"
39 #include "ClkClockApp.h"
40 #include "ClkCommonLib.h"
41 #include "ClkDefaultCustomItem.h"
42 #include "ClkDropDownCustomItem.h"
43 #include "ClkDropdownAndRepeatCustomItem.h"
44 #include "ClkEditSnoozeForm.h"
45 #include "ClkRadioCustomItem.h"
46 #include "ClkSceneRegister.h"
47 #include "ClkToggleCustomItem.h"
48 #include "ClkTypes.h"
49
50 using namespace Tizen::App;
51 using namespace Tizen::Base;
52 using namespace Tizen::Base::Collection;
53 using namespace Tizen::Graphics;
54 using namespace Tizen::Io;
55 using namespace Tizen::Media;
56 using namespace Tizen::Text;
57 using namespace Tizen::Ui;
58 using namespace Tizen::Ui::Controls;
59 using namespace Tizen::Ui::Scenes;
60 using namespace Tizen::System;
61
62 static const int IDA_CREATE_ALARM_SAVE = 201;
63 static const int IDA_CREATE_ALARM_CANCEL = 202;
64 static const int IDA_HEADER_ITEM_SAVE = 203;
65 static const int IDA_HEADER_ITEM_CANCEL = 204;
66 static const int IDA_BUTTON_HOURS = 205;
67 static const int IDA_BUTTON_MINS = 206;
68 static const int IDA_BUTTON_TOGGLE = 207;
69 static const int IDA_BUTTON_MORE = 208;
70 static const int IDA_BUTTON_SUN = 209;
71 static const int IDA_BUTTON_MON = 210;
72 static const int IDA_BUTTON_TUE = 211;
73 static const int IDA_BUTTON_WED = 212;
74 static const int IDA_BUTTON_THU = 213;
75 static const int IDA_BUTTON_FRI = 214;
76 static const int IDA_BUTTON_SAT = 215;
77 const RequestId REQUEST_ID_TERMINATE = 20000;
78
79 AlarmEditorForm::AlarmEditorForm(void)
80 : __alarmName("")
81 , __audioFilePath(AlarmPresentationModel::GetInstance()->defaultAudioPath)
82 , __defaultEditFieldValue("")
83 , __defaultToggleValue(CommonUtil::GetString(L"IDS_COM_BODY_AM"))
84 , __pDuration(null)
85 , __fontValue(0)
86 , __hourText("")
87 , __isAppControlCompleted(false)
88 , __isPlaying(false)
89 , __isSnoozeOn(true)
90 , __modalMsgBoxResult(0)
91 , __pAlarm(null)
92 , __pBtnDayFri(null)
93 , __pBtnDayMon(null)
94 , __pBtnDaySat(null)
95 , __pBtnDaySun(null)
96 , __pBtnDayThu(null)
97 , __pBtnDayTue(null)
98 , __pBtnDayWed(null)
99 , __pBtnHourDisplay(null)
100 , __pBtnMinDisplay(null)
101 , __pBtnMore(null)
102 , __pBtnToggle(null)
103 , __pEditField(null)
104 , __pGroupedListView(null)
105 , __pHourImf(null)
106 , __pLabelAm(null)
107 , __pLabelEditfieldTitle(null)
108 , __pLabelPm(null)
109 , __pLabelTitle(null)
110 , __player(null)
111 , __pListView(null)
112 , __pMinImf(null)
113 , __pOldAlarm(null)
114 , __pPanelDays(null)
115 , __pPanelEditTime(null)
116 , __pPanelList(null)
117 , __pResetPopup(null)
118 , __pScrollPanel(null)
119 , __pSlider(null)
120 , __pRepeat(null)
121 , __repeatName(L"")
122 , __selectedIndex(1)
123 , __showMessageBox(true)
124 , __showRepeat(false)
125 , __showType(false)
126 , __sliderDefaultValue(13)
127 , __sliderValue(0)
128 , __snoozeDurationValue("")
129 , __snoozeStatus(false)
130 , __snoozeValue(0)
131 , __textLength(0)
132 , __typeName(0)
133 , __typeNameValue("")
134 , is24HourFormat(false)
135
136 {
137
138 }
139
140 AlarmEditorForm::~AlarmEditorForm(void)
141 {
142         if (__pDuration != null)
143         {
144                 delete __pDuration;
145                 __pDuration = null;
146         }
147
148         if (__pRepeat != null)
149         {
150                 delete __pRepeat;
151                 __pRepeat = null;
152         }
153         if (__player == null)
154         {
155                 return;
156         }
157
158         PlayerState estate = __player->GetState();
159         if ((estate == PLAYER_STATE_OPENED) || (estate == PLAYER_STATE_PAUSED)
160                         || (estate == PLAYER_STATE_PLAYING)
161                         || (estate == PLAYER_STATE_ENDOFCLIP) || (estate == PLAYER_STATE_STOPPED))
162         {
163                 __player->Close();
164         }
165
166         if (__player)
167         {
168                 delete __player;
169                 __player = null;
170         }
171
172         SettingInfo::RemoveSettingEventListener(*this);
173         DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
174 }
175
176 bool
177 AlarmEditorForm::Initialize(void)
178 {
179         result r = E_FAILURE;
180
181         r = Construct(L"IDL_ALARM_EDITOR_FORM");
182
183         if (IsFailed(r))
184         {
185                 return false;
186         }
187
188         return true;
189 }
190
191 result
192 AlarmEditorForm::OnInitializing(void)
193 {
194         result r = E_SUCCESS;
195         Bitmap* pBgNormalBitmap = null;
196         Bitmap* pDayNormalBitmap = null;
197         Bitmap* pDayFocusBitmap = null;
198         Bitmap* pFinalBitmap = null;
199         Bitmap* pbgFocusBitmap = null;
200         Bitmap* pbgBitmap = null;
201         Bitmap* pFinalBitmapFocused = null;
202         Canvas* pCanvas = null;
203         Canvas* pCanvasFocused = null;
204         int canvasWidth = 276;
205         int canvasHeight = 236;
206         String newAlarm;
207         String labelText;
208         String durationValue;
209
210         SettingInfo::GetValue(L"http://tizen.org/setting/locale.time.format.24hour", is24HourFormat);
211         SettingInfo::AddSettingEventListener(*this);
212
213         AddTouchEventListener(*this);
214         AddOrientationEventListener(*this);
215         DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD,*this);
216
217         __snoozeDurationValue.Clear();
218         __snoozeDurationValue.Append(CommonUtil::GetString(L"IDS_ALM_BODY_5MINS"));
219         __snoozeDurationValue.Append(L", ");
220         __snoozeDurationValue.Append(CommonUtil::GetString(L"IDS_ALM_BODY_3TIMES"));
221
222         __defaultEditFieldValue = CommonUtil::GetString(L"IDS_COM_BODY_ALARM");
223         __defaultEditFieldValue.Append("1");
224
225         SetFormBackEventListener(this);
226         SceneManager::GetInstance()->AddSceneEventListener(IDSCN_CREATE_ALARM, *this);
227
228         __pScrollPanel = static_cast<ScrollPanel*>(GetControl("IDC_SCROLLPANEL1", false));
229
230         if (__pScrollPanel != null)
231         {
232                 __pScrollPanel->AddTouchEventListener(*this);
233                 __pScrollPanel->SetScrollBarVisible(false);
234         }
235         AddFocusEventListener(*this);
236         __pLabelEditfieldTitle = static_cast<Label*>(GetControl("IDC_LABEL1", true));
237
238         GetFooter()->AddActionEventListener(*this);
239
240         __pLabelTitle = static_cast<Label*>(GetControl("IDC_LABEL_TITLE", true));
241
242         if (__pLabelTitle != null)
243         {
244                 newAlarm = CommonUtil::GetString("IDS_COM_SK_NEW");
245                 newAlarm.Append(" ");
246                 newAlarm.Append(CommonUtil::GetString("IDS_COM_BODY_ALARM"));
247                 newAlarm.ToUpper(labelText);
248                 __pLabelTitle->SetText(labelText);
249         }
250
251         __pPanelList = static_cast<Panel*>(GetControl("IDC_PANEL_LIST", true));
252
253         __pSlider = static_cast<Slider *>(GetControl("IDC_SLIDER_VOLUME", true));
254         __pSlider->SetValue(__sliderDefaultValue);
255         __pSlider->AddSliderEventListener(*this);
256 //      __pSlider->AddTouchEventListener(*this);
257         __pSlider->AddFocusEventListener(*this);
258         __pSlider->AddAdjustmentEventListener(*this);
259         __pEditField = static_cast<EditField*>(GetControl("IDC_EDITFIELD1", true));
260
261         if (__pEditField == null)
262         {
263                 return E_FAILURE;
264         }
265
266         __pEditField->SetText(__defaultEditFieldValue);
267         __pEditField->AddTextEventListener(*this);
268         __pEditField->AddKeypadEventListener(*this);
269         __pEditField->AddFocusEventListener(*this);
270         __pEditField->SetOverlayKeypadCommandButtonVisible(false);
271         __pEditField->SetEditTextFilter(this);
272         __pPanelEditTime = static_cast<Panel*>(GetControl("IDC_PANEL_EDITTIME", true));
273
274         if (__pPanelEditTime == null)
275         {
276                 return E_FAILURE;
277         }
278
279         __pPanelEditTime->AddTouchEventListener(*this);
280
281         pBgNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_NORMAL_BG);
282         pbgBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_BG);
283
284         pCanvas = new (std::nothrow) Canvas();
285         pCanvas->Construct(Rectangle(0,0,canvasWidth,canvasHeight));
286         pCanvas->DrawBitmap(Point(0,0),*pBgNormalBitmap);
287         pCanvas->DrawBitmap(Point(0,0),*pbgBitmap);
288
289         if (pBgNormalBitmap != null)
290         {
291                 delete pBgNormalBitmap;
292                 pBgNormalBitmap = null;
293         }
294
295         pFinalBitmap = new (std::nothrow) Bitmap();
296
297         if ( pFinalBitmap != NULL)
298         {
299                 pFinalBitmap->Construct(*pCanvas,Rectangle(0,0,canvasWidth,canvasHeight));
300                 delete pCanvas;
301         }
302
303         pbgFocusBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_FOCUS_BG);
304
305         pCanvasFocused = new (std::nothrow) Canvas();
306         pCanvasFocused->Construct(Rectangle(0,0,canvasWidth,canvasHeight));
307         pCanvasFocused->DrawBitmap(Point(0,0),*pbgFocusBitmap);
308         pCanvasFocused->DrawBitmap(Point(0,0),*pbgBitmap);
309
310         if (pbgFocusBitmap != null)
311         {
312                 delete pbgFocusBitmap;
313                 pbgFocusBitmap = null;
314         }
315
316         if (pbgBitmap != null)
317         {
318                 delete pbgBitmap;
319                 pbgBitmap = null;
320         }
321
322         pFinalBitmapFocused = new (std::nothrow) Bitmap();
323
324         if ( pFinalBitmapFocused != null)
325         {
326                 pFinalBitmapFocused->Construct(*pCanvasFocused,Rectangle(0,0,canvasWidth,canvasHeight));
327                 delete pCanvasFocused;
328         }
329
330
331         __pBtnHourDisplay = dynamic_cast<Button*>(GetControl("IDC_BUTTON_HOUR", true));
332
333         if (__pBtnHourDisplay == null)
334         {
335                 if (pFinalBitmapFocused != null)
336                 {
337                         delete pFinalBitmapFocused;
338                         pFinalBitmapFocused = null;
339                 }
340
341                 if (pFinalBitmap != null)
342                 {
343                         delete pFinalBitmap;
344                         pFinalBitmap = null;
345                 }
346
347                 return E_FAILURE;
348         }
349
350         __pBtnHourDisplay->SetActionId(IDA_BUTTON_HOURS);
351         __pBtnHourDisplay->AddActionEventListener(*this);
352         __pBtnHourDisplay->SetNormalBackgroundBitmap(*pFinalBitmap);
353         __pBtnHourDisplay->SetPressedBackgroundBitmap(*pFinalBitmapFocused);
354         __pBtnHourDisplay->SetFocusable(true);
355         __pBtnHourDisplay->AddFocusEventListener(*this);
356         __pBtnHourDisplay->AddTouchEventListener(*this);
357         __pBtnHourDisplay->SetPropagatedKeyEventListener(this);
358
359         __pHourImf = new (std::nothrow) InputConnection();
360         __pHourImf->Construct(__pBtnHourDisplay, *this, *this);
361         __pHourImf->SetInputPanelStyle(INPUT_PANEL_STYLE_NUMBER_ONLY);
362         //__pHourImf->SetInputPanelActionEnabled(false);
363
364         __pBtnMinDisplay = dynamic_cast<Button*>(GetControl("IDC_BUTTON_MIN", true));
365
366         if (__pBtnMinDisplay == null)
367         {
368                 if (pFinalBitmapFocused != null)
369                 {
370                         delete pFinalBitmapFocused;
371                         pFinalBitmapFocused = null;
372                 }
373
374                 if (pFinalBitmap != null)
375                 {
376                         delete pFinalBitmap;
377                         pFinalBitmap = null;
378                 }
379
380                 return E_FAILURE;
381         }
382
383         __pBtnMinDisplay->SetActionId(IDA_BUTTON_MINS);
384         __pBtnMinDisplay->AddActionEventListener(*this);
385         __pBtnMinDisplay->SetNormalBackgroundBitmap(*pFinalBitmap);
386         __pBtnMinDisplay->SetPressedBackgroundBitmap(*pFinalBitmapFocused);
387         __pBtnMinDisplay->SetFocusable(true);
388         __pBtnMinDisplay->AddFocusEventListener(*this);
389         __pBtnMinDisplay->AddTouchEventListener(*this);
390         __pBtnMinDisplay->SetPropagatedKeyEventListener(this);
391
392
393         __pMinImf = new (std::nothrow) InputConnection();
394         __pMinImf->Construct(__pBtnMinDisplay, *this, *this);
395         __pMinImf->SetInputPanelStyle(INPUT_PANEL_STYLE_NUMBER_ONLY);
396         //__pMinImf->SetInputPanelActionEnabled(false);
397
398         __pBtnToggle = dynamic_cast<Button*>(GetControl("IDC_BUTTON_TOGGLE", true));
399
400         if (__pBtnToggle == null)
401         {
402                 if (pFinalBitmapFocused != null)
403                 {
404                         delete pFinalBitmapFocused;
405                         pFinalBitmapFocused = null;
406                 }
407
408                 if (pFinalBitmap != null)
409                 {
410                         delete pFinalBitmap;
411                         pFinalBitmap = null;
412                 }
413
414                 return E_FAILURE;
415         }
416
417         __pBtnToggle->SetActionId(IDA_BUTTON_TOGGLE);
418         __pBtnToggle->AddActionEventListener(*this);
419         __pBtnToggle->AddTouchEventListener(*this);
420
421         __pLabelAm = dynamic_cast<Label*>(GetControl("IDC_LABEL_AM", true));
422         __pLabelPm = dynamic_cast<Label*>(GetControl("IDC_LABEL_PM", true));
423
424
425
426         __pPanelDays = static_cast<Panel*>(GetControl("IDC_PANEL_DAYS", true));
427
428         if (__pPanelDays == null)
429         {
430                 if (pFinalBitmapFocused != null)
431                 {
432                         delete pFinalBitmapFocused;
433                         pFinalBitmapFocused = null;
434                 }
435
436                 if (pFinalBitmap != null)
437                 {
438                         delete pFinalBitmap;
439                         pFinalBitmap = null;
440                 }
441                 AppLog("Coming here");
442                 return E_FAILURE;
443         }
444
445         __pPanelDays->AddTouchEventListener(*this);
446         __pBtnMore = dynamic_cast<Button*>(GetControl("IDC_BUTTON_MORE", true));
447
448         if (__pBtnMore == null)
449         {
450                 if (pFinalBitmapFocused != null)
451                 {
452                         delete pFinalBitmapFocused;
453                         pFinalBitmapFocused = null;
454                 }
455
456                 if (pFinalBitmap != null)
457                 {
458                         delete pFinalBitmap;
459                         pFinalBitmap = null;
460                 }
461
462                 return E_FAILURE;
463         }
464
465         __pBtnMore->SetActionId(IDA_BUTTON_MORE);
466         __pBtnMore->AddActionEventListener(*this);
467         __pPanelList = static_cast<Panel*>(GetControl("IDC_PANEL_LIST", true));
468
469         if (__pPanelList == null)
470         {
471                 if (pFinalBitmapFocused != null)
472                 {
473                         delete pFinalBitmapFocused;
474                         pFinalBitmapFocused = null;
475                 }
476
477                 if (pFinalBitmap != null)
478                 {
479                         delete pFinalBitmap;
480                         pFinalBitmap = null;
481                 }
482
483                 return E_FAILURE;
484         }
485
486         __pPanelList->SetShowState(false);
487         __pPanelList->SetFocusable(false);
488
489         __pBtnDaySun = dynamic_cast<Button*>(GetControl("IDC_BUTTON_SUN", true));
490
491         if (__pBtnDaySun == null)
492         {
493                 if (pFinalBitmapFocused != null)
494                 {
495                         delete pFinalBitmapFocused;
496                         pFinalBitmapFocused = null;
497                 }
498
499                 if (pFinalBitmap != null)
500                 {
501                         delete pFinalBitmap;
502                         pFinalBitmap = null;
503                 }
504
505                 return E_FAILURE;
506         }
507
508         pBgNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_BG);
509         pbgBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_FOCUS_BG);
510
511         AppLog("the width:%d height: %d",pBgNormalBitmap->GetWidth(),pBgNormalBitmap->GetHeight() );
512         __pBtnDaySun->SetActionId(IDA_BUTTON_SUN);
513         __pBtnDaySun->AddActionEventListener(*this);
514         __pBtnDaySun->SetNormalBackgroundBitmap(*pBgNormalBitmap);
515         __pBtnDaySun->SetPressedBackgroundBitmap(*pbgBitmap);
516         __pBtnDaySun->AddTouchEventListener(*this);
517
518         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_SUN_BG);
519         pDayFocusBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_SUN_FOCUS_BG);
520
521         __pBtnDaySun->SetNormalBitmap(Point(0,0), *pDayNormalBitmap);
522         __pBtnDaySun->SetPressedBitmap(Point(0,0), *pDayFocusBitmap);
523
524         if (pDayNormalBitmap != null)
525         {
526                 delete pDayNormalBitmap;
527                 pDayNormalBitmap = null;
528         }
529
530         if (pDayFocusBitmap != null)
531         {
532                 delete pDayFocusBitmap;
533                 pDayFocusBitmap = null;
534         }
535
536         __pBtnDayMon = dynamic_cast<Button*>(GetControl("IDC_BUTTON_MON", true));
537
538         if (__pBtnDayMon == NULL)
539         {
540                 if (pFinalBitmapFocused != null)
541                 {
542                         delete pFinalBitmapFocused;
543                         pFinalBitmapFocused = null;
544                 }
545
546                 if (pFinalBitmap != null)
547                 {
548                         delete pFinalBitmap;
549                         pFinalBitmap = null;
550                 }
551
552                 if (pBgNormalBitmap != null)
553                 {
554                         delete pBgNormalBitmap;
555                         pBgNormalBitmap = null;
556                 }
557
558                 if (pbgBitmap != null)
559                 {
560                         delete pbgBitmap;
561                         pbgBitmap = null;
562                 }
563
564                 return E_FAILURE;
565         }
566
567         __pBtnDayMon->SetActionId(IDA_BUTTON_MON);
568         __pBtnDayMon->AddActionEventListener(*this);
569         __pBtnDayMon->SetNormalBackgroundBitmap(*pBgNormalBitmap);
570         __pBtnDayMon->SetPressedBackgroundBitmap(*pbgBitmap);
571         __pBtnDayMon->AddTouchEventListener(*this);
572
573         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_MON_BG);
574         pDayFocusBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_MON_FOCUS_BG);
575
576         __pBtnDayMon->SetNormalBitmap(Point(0,0), *pDayNormalBitmap);
577         __pBtnDayMon->SetPressedBitmap(Point(0,0), *pDayFocusBitmap);
578
579         if (pDayNormalBitmap != null)
580         {
581                 delete pDayNormalBitmap;
582                 pDayNormalBitmap = null;
583         }
584
585         if (pDayFocusBitmap != null)
586         {
587                 delete pDayFocusBitmap;
588                 pDayFocusBitmap = null;
589         }
590
591         __pBtnDayTue = dynamic_cast<Button*>(GetControl("IDC_BUTTON_TUE", true));
592
593         if (__pBtnDayTue == NULL)
594         {
595                 if (pFinalBitmapFocused != null)
596                 {
597                         delete pFinalBitmapFocused;
598                         pFinalBitmapFocused = null;
599                 }
600
601                 if (pFinalBitmap != null)
602                 {
603                         delete pFinalBitmap;
604                         pFinalBitmap = null;
605                 }
606
607                 if (pBgNormalBitmap != null)
608                 {
609                         delete pBgNormalBitmap;
610                         pBgNormalBitmap = null;
611                 }
612
613                 if (pbgBitmap != null)
614                 {
615                         delete pbgBitmap;
616                         pbgBitmap = null;
617                 }
618
619                 return E_FAILURE;
620         }
621
622         __pBtnDayTue->SetActionId(IDA_BUTTON_TUE);
623         __pBtnDayTue->AddActionEventListener(*this);
624         __pBtnDayTue->SetNormalBackgroundBitmap(*pBgNormalBitmap);
625         __pBtnDayTue->SetPressedBackgroundBitmap(*pbgBitmap);
626         __pBtnDayTue->AddTouchEventListener(*this);
627
628         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_TUE_BG);
629         pDayFocusBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_TUE_FOCUS_BG);
630
631         __pBtnDayTue->SetNormalBitmap(Point(0,0), *pDayNormalBitmap);
632         __pBtnDayTue->SetPressedBitmap(Point(0,0), *pDayFocusBitmap);
633
634         if (pDayNormalBitmap != null)
635         {
636                 delete pDayNormalBitmap;
637                 pDayNormalBitmap = null;
638         }
639
640         if (pDayFocusBitmap != null)
641         {
642                 delete pDayFocusBitmap;
643                 pDayFocusBitmap = null;
644         }
645
646         __pBtnDayWed = dynamic_cast<Button*>(GetControl("IDC_BUTTON_WED", true));
647
648         if (__pBtnDayWed == NULL)
649         {
650                 if (pFinalBitmapFocused != null)
651                 {
652                         delete pFinalBitmapFocused;
653                         pFinalBitmapFocused = null;
654                 }
655
656                 if (pFinalBitmap != null)
657                 {
658                         delete pFinalBitmap;
659                         pFinalBitmap = null;
660                 }
661
662                 if (pBgNormalBitmap != null)
663                 {
664                         delete pBgNormalBitmap;
665                         pBgNormalBitmap = null;
666                 }
667
668                 if (pbgBitmap != null)
669                 {
670                         delete pbgBitmap;
671                         pbgBitmap = null;
672                 }
673
674                 return E_FAILURE;
675         }
676
677         __pBtnDayWed->SetActionId(IDA_BUTTON_WED);
678         __pBtnDayWed->AddActionEventListener(*this);
679         __pBtnDayWed->SetNormalBackgroundBitmap(*pBgNormalBitmap);
680         __pBtnDayWed->SetPressedBackgroundBitmap(*pbgBitmap);
681         __pBtnDayWed->AddTouchEventListener(*this);
682
683         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_WED_BG);
684         pDayFocusBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_WED_FOCUS_BG);
685
686         __pBtnDayWed->SetNormalBitmap(Point(0,0), *pDayNormalBitmap);
687         __pBtnDayWed->SetPressedBitmap(Point(0,0), *pDayFocusBitmap);
688
689         if (pDayNormalBitmap != null)
690         {
691                 delete pDayNormalBitmap;
692                 pDayNormalBitmap = null;
693         }
694
695         if (pDayFocusBitmap != null)
696         {
697                 delete pDayFocusBitmap;
698                 pDayFocusBitmap = null;
699         }
700
701         __pBtnDayThu = dynamic_cast<Button*>(GetControl("IDC_BUTTON_THU", true));
702
703         if (__pBtnDayThu == NULL)
704         {
705                 if (pFinalBitmapFocused != null)
706                 {
707                         delete pFinalBitmapFocused;
708                         pFinalBitmapFocused = null;
709                 }
710
711                 if (pFinalBitmap != null)
712                 {
713                         delete pFinalBitmap;
714                         pFinalBitmap = null;
715                 }
716
717                 if (pBgNormalBitmap != null)
718                 {
719                         delete pBgNormalBitmap;
720                         pBgNormalBitmap = null;
721                 }
722
723                 if (pbgBitmap != null)
724                 {
725                         delete pbgBitmap;
726                         pbgBitmap = null;
727                 }
728
729                 return E_FAILURE;
730         }
731
732         __pBtnDayThu->SetActionId(IDA_BUTTON_THU);
733         __pBtnDayThu->AddActionEventListener(*this);
734         __pBtnDayThu->SetNormalBackgroundBitmap(*pBgNormalBitmap);
735         __pBtnDayThu->SetPressedBackgroundBitmap(*pbgBitmap);
736         __pBtnDayThu->AddTouchEventListener(*this);
737
738         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_THU_BG);
739         pDayFocusBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_THU_FOCUS_BG);
740
741         __pBtnDayThu->SetNormalBitmap(Point(0,0), *pDayNormalBitmap);
742         __pBtnDayThu->SetPressedBitmap(Point(0,0), *pDayFocusBitmap);
743
744         if (pDayNormalBitmap != null)
745         {
746                 delete pDayNormalBitmap;
747                 pDayNormalBitmap = null;
748         }
749
750         if (pDayFocusBitmap != null)
751         {
752                 delete pDayFocusBitmap;
753                 pDayFocusBitmap = null;
754         }
755
756         __pBtnDayFri = dynamic_cast<Button*>(GetControl("IDC_BUTTON_FRI", true));
757
758         if (__pBtnDayFri == NULL)
759         {
760                 if (pFinalBitmapFocused != null)
761                 {
762                         delete pFinalBitmapFocused;
763                         pFinalBitmapFocused = null;
764                 }
765
766                 if (pFinalBitmap != null)
767                 {
768                         delete pFinalBitmap;
769                         pFinalBitmap = null;
770                 }
771
772                 if (pBgNormalBitmap != null)
773                 {
774                         delete pBgNormalBitmap;
775                         pBgNormalBitmap = null;
776                 }
777
778                 if (pbgBitmap != null)
779                 {
780                         delete pbgBitmap;
781                         pbgBitmap = null;
782                 }
783
784                 return E_FAILURE;
785         }
786
787         __pBtnDayFri->SetActionId(IDA_BUTTON_FRI);
788         __pBtnDayFri->AddActionEventListener(*this);
789         __pBtnDayFri->SetNormalBackgroundBitmap(*pBgNormalBitmap);
790         __pBtnDayFri->SetPressedBackgroundBitmap(*pbgBitmap);
791         __pBtnDayFri->AddTouchEventListener(*this);
792
793         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_FRI_BG);
794         pDayFocusBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_FRI_FOCUS_BG);
795
796         __pBtnDayFri->SetNormalBitmap(Point(0,0), *pDayNormalBitmap);
797         __pBtnDayFri->SetPressedBitmap(Point(0,0), *pDayFocusBitmap);
798
799         if (pDayNormalBitmap != null)
800         {
801                 delete pDayNormalBitmap;
802                 pDayNormalBitmap = null;
803         }
804
805         if (pDayFocusBitmap != null)
806         {
807                 delete pDayFocusBitmap;
808                 pDayFocusBitmap = null;
809         }
810
811         __pBtnDaySat = dynamic_cast<Button*>(GetControl("IDC_BUTTON_SAT", true));
812
813         if (__pBtnDaySat == NULL)
814         {
815                 if (pFinalBitmapFocused != null)
816                 {
817                         delete pFinalBitmapFocused;
818                         pFinalBitmapFocused = null;
819                 }
820
821                 if (pFinalBitmap != null)
822                 {
823                         delete pFinalBitmap;
824                         pFinalBitmap = null;
825                 }
826
827                 if (pBgNormalBitmap != null)
828                 {
829                         delete pBgNormalBitmap;
830                         pBgNormalBitmap = null;
831                 }
832
833                 if (pbgBitmap != null)
834                 {
835                         delete pbgBitmap;
836                         pbgBitmap = null;
837                 }
838
839                 return E_FAILURE;
840         }
841
842         __pBtnDaySat->SetActionId(IDA_BUTTON_SAT);
843         __pBtnDaySat->AddActionEventListener(*this);
844         __pBtnDaySat->AddFocusEventListener(*this);
845         __pBtnDaySat->SetNormalBackgroundBitmap(*pBgNormalBitmap);
846         __pBtnDaySat->SetPressedBackgroundBitmap(*pbgBitmap);
847         __pBtnDaySat->AddTouchEventListener(*this);
848
849         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_SAT_BG);
850         pDayFocusBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_SAT_FOCUS_BG);
851
852         __pBtnDaySat->SetNormalBitmap(Point(0,0), *pDayNormalBitmap);
853         __pBtnDaySat->SetPressedBitmap(Point(0,0), *pDayFocusBitmap);
854
855         if (pDayNormalBitmap != null)
856         {
857                 delete pDayNormalBitmap;
858                 pDayNormalBitmap = null;
859         }
860
861         if (pDayFocusBitmap != null)
862         {
863                 delete pDayFocusBitmap;
864                 pDayFocusBitmap = null;
865         }
866
867         if (pBgNormalBitmap != null)
868         {
869                 delete pBgNormalBitmap;
870                 pBgNormalBitmap = null;
871         }
872
873         if (pbgBitmap != null)
874         {
875                 delete pbgBitmap;
876                 pbgBitmap = null;
877         }
878
879         __pGroupedListView = static_cast<GroupedListView*>(GetControl("IDC_GROUPEDLISTVIEW1", true));
880
881         if (__pGroupedListView != null)
882         {
883                 __pGroupedListView->AddGroupedListViewItemEventListener(*this);
884                 __pGroupedListView->AddTouchEventListener(*this);
885                 __pGroupedListView->SetItemProvider(*this);
886                 __pGroupedListView->SetFocusable(true);
887         }
888
889         __pListView = dynamic_cast<ListView*>(GetControl("IDC_LISTVIEW1", true));
890
891         if (__pListView != null)
892         {
893                 __pListView->AddListViewItemEventListener(*this);
894                 __pListView->AddTouchEventListener(*this);
895                 __pListView->SetItemProvider(*this);
896         }
897
898         __selectedIndexValues.Construct();
899
900         __player = new (std::nothrow) Player();
901         if ( __player == null)
902         {
903                 AppLogException("pPlyaer = new (std::nothrow) Player() has failed");
904                 return E_FAILURE;
905         }
906         __player->Construct(*this);
907
908         GetHeader()->SetTitleText(__pEditField->GetText());
909         GetHeader()->SetShowState(false);
910         GetHeader()->AddActionEventListener(*this);
911
912         if (pFinalBitmapFocused != null)
913         {
914                 delete pFinalBitmapFocused;
915                 pFinalBitmapFocused = null;
916         }
917
918         if (pFinalBitmap != null)
919         {
920                 delete pFinalBitmap;
921                 pFinalBitmap = null;
922         }
923
924         __pBtnMinDisplay->SetNextFocus(__pBtnToggle);
925         __pBtnToggle->SetPreviousFocus(__pBtnMinDisplay);
926
927         return r;
928 }
929
930 result
931 AlarmEditorForm::OnTerminating(void)
932 {
933         result r = E_SUCCESS;
934
935         if (__pHourImf)
936         {
937                 delete __pHourImf;
938                 __pHourImf = null;
939         }
940         if (__pMinImf)
941         {
942                 delete __pMinImf;
943                 __pMinImf = null;
944         }
945
946         return r;
947 }
948
949 void
950 AlarmEditorForm::OnActionPerformed(const Control& source, int actionId)
951 {
952         AppLog("Action id: %d", actionId);
953         SceneManager* pSceneManager = SceneManager::GetInstance();
954         AlarmPresentationModel* pAlarmPresentationModel = AlarmPresentationModel::GetInstance();
955         DataServiceProvider* pDataServiceProvider = DataServiceProvider::GetInstance();
956         DateTime currentTime;
957         DateTime alarmTime;
958         int duration = 0;
959         int repeat = 0;
960         ArrayList* pArgList = null;
961         String alarmName = L"";
962         Bitmap* pDayNormalBitmap = null;
963         Bitmap* pDayFocusBitmap = null;
964         result r = E_FAILURE;
965
966         /*      if (__pEditField != null)
967         {
968                 __pEditField->HideKeypad();
969                 __pEditField->Invalidate(false);
970         }*/
971
972         switch (actionId)
973         {
974         case IDA_CREATE_ALARM_CANCEL:
975         {
976                 pSceneManager->GoBackward(BackwardSceneTransition());
977         }
978         break;
979
980         case IDA_HEADER_ITEM_SAVE:
981         case IDA_CREATE_ALARM_SAVE:
982         {
983                 int hour, minute;
984                 String hourVal, minVal;
985                 String alarmTone;
986                 int alarmVol;
987                 DateTime time;
988
989                 minVal = __pBtnMinDisplay->GetText();
990                 Integer::Parse(minVal, minute);
991
992                 pArgList = new (std::nothrow) ArrayList();
993                 pDataServiceProvider->GetCurrentDateTime(currentTime);
994
995                 if (__pEditField != null)
996                 {
997                         alarmName = __pEditField->GetText();
998                 }
999
1000                 hourVal = __pBtnHourDisplay->GetText();
1001                 Integer::Parse(hourVal, hour);
1002
1003                 if (is24HourFormat == false)
1004                 {
1005                         if (__defaultToggleValue == CommonUtil::GetString(L"IDS_COM_BODY_AM"))
1006                         {
1007
1008                                 if(hour == 12)
1009                                 {
1010                                         hour = 0;
1011                                 }
1012
1013                         }
1014                         else if (__defaultToggleValue == CommonUtil::GetString(L"IDS_COM_POP_PM"))
1015                         {
1016
1017                                 if(hour != 12)
1018                                 {
1019                                         hour = hour + 12;
1020                                 }
1021
1022                         }
1023                 }
1024
1025                 alarmTime.SetValue(1900, 1, 1, hour, minute, 0);
1026
1027                 if (__pDuration != null && __pRepeat != null)
1028                 {
1029                         duration = __pDuration->ToInt();
1030                         repeat = __pRepeat->ToInt();
1031                 }
1032
1033                 __pAlarm->SetAlarmOnState(1);
1034                 __pAlarm->SetAlarmName(alarmName);
1035                 __pAlarm->SetAlarmTime(alarmTime);
1036
1037
1038                 if (__pSlider != null)
1039                 {
1040                         alarmVol = __pSlider->GetValue();
1041                         __pAlarm->SetRingVolume(alarmVol);
1042                 }
1043
1044                 if (__typeName == 0)
1045                 {
1046                         __pAlarm->SetRingType(ALARM_TYPE_MELODY);
1047                 }
1048                 else if (__typeName == 1)
1049                 {
1050                         __pAlarm->SetRingType(ALARM_TYPE_VIBRATION);
1051                 }
1052                 else if (__typeName == 2)
1053                 {
1054                         __pAlarm->SetRingType(ALARM_TYPE_MELODY_AND_VIBRATION);
1055                 }
1056
1057
1058                 __pAlarm->SetSnoozeDuration(duration);
1059                 __pAlarm->SetSnoozeRepeat(repeat);
1060                 __pAlarm->SetLastRingingTime(time);
1061                 __pAlarm->SetSnoozeRepeatCount(__pAlarm->GetSnoozeRepeat());
1062
1063                 if (__pAlarm->GetAlarmId() != 0)
1064                 {
1065                         r = pAlarmPresentationModel->UpdateAlarm(*__pOldAlarm, *__pAlarm);
1066                 }
1067                 else
1068                 {
1069                         r = pAlarmPresentationModel->SaveAlarm(*__pAlarm);
1070                 }
1071
1072                 AppLog("result: %s", GetErrorMessage(r));
1073                 if (r == E_STORAGE_FULL || r == E_INIT_FAILED || r == E_OUT_OF_MEMORY)
1074                 {
1075                         MessageBox msgBox;
1076                         String msg = CommonUtil::GetString("IDS_MEMORY_FULL");
1077                         r = msgBox.Construct(L"", msg, MSGBOX_STYLE_NONE, 3000);
1078                         AppLog("the result is %s", GetErrorMessage(r));
1079                         msgBox.ShowAndWait(__modalMsgBoxResult);
1080                 }
1081
1082                 if (pArgList != null)
1083                 {
1084                         pArgList->Construct();
1085                         pArgList->Add(*new (std::nothrow) AlarmData(*__pAlarm));
1086
1087                         if (pSceneManager != null)
1088                         {
1089                                 pSceneManager->GoBackward(BackwardSceneTransition(), pArgList);
1090                         }
1091                 }
1092
1093                 if (pArgList != null)
1094                 {
1095                         delete pArgList;
1096                         pArgList = null;
1097                 }
1098                 /*if (pOldAlarm != null)
1099                 {
1100                         delete pOldAlarm;
1101                         pOldAlarm = null;
1102                 }*/
1103         }
1104         break;
1105
1106         case IDA_HEADER_ITEM_CANCEL:
1107         {
1108                 pSceneManager->GoBackward(BackwardSceneTransition());
1109         }
1110         break;
1111
1112         case IDA_BUTTON_MORE:
1113         {
1114
1115                 if (__pBtnHourDisplay->HasFocus())
1116                 {
1117                         HideHourKeypad();
1118                         SetFocus();
1119                 }
1120                 else if (__pBtnMinDisplay->HasFocus())
1121                 {
1122                         HideMinKeypad();
1123                         SetFocus();
1124                 }
1125
1126                 __pPanelList->SetShowState(true);
1127                 __pScrollPanel->SetScrollBarVisible(true);
1128                 __pBtnMore->SetShowState(false);
1129                 //Invalidate(true);
1130                 RearrangeControls();
1131                 GetFooter()->SetFocusable(false);
1132
1133         }
1134         break;
1135
1136         case IDA_BUTTON_TOGGLE:
1137         {
1138                 Bitmap* pToggleBtnPMBG = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_TOGGLE_PM_BG);
1139                 Bitmap* pToggleBtnAMBG = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_TOGGLE_AM_BG);
1140
1141                 if (__defaultToggleValue == CommonUtil::GetString(L"IDS_COM_BODY_AM"))
1142                 {
1143                         __pBtnToggle->SetNormalBackgroundBitmap(*pToggleBtnPMBG);
1144                         __pBtnToggle->SetPressedBackgroundBitmap(*pToggleBtnPMBG);
1145                         __defaultToggleValue = CommonUtil::GetString(L"IDS_COM_POP_PM");
1146                 }
1147                 else if (__defaultToggleValue == CommonUtil::GetString(L"IDS_COM_POP_PM"))
1148                 {
1149                         __pBtnToggle->SetNormalBackgroundBitmap(*pToggleBtnAMBG);
1150                         __pBtnToggle->SetPressedBackgroundBitmap(*pToggleBtnAMBG);
1151                         __defaultToggleValue = CommonUtil::GetString(L"IDS_COM_BODY_AM");
1152                 }
1153
1154                 if (pToggleBtnPMBG != null)
1155                 {
1156                         delete pToggleBtnPMBG;
1157                         pToggleBtnPMBG = null;
1158                 }
1159
1160                 if (pToggleBtnAMBG != null)
1161                 {
1162                         delete pToggleBtnAMBG;
1163                         pToggleBtnAMBG = null;
1164                 }
1165
1166                 __pBtnToggle->Invalidate(true);
1167
1168         }
1169         break;
1170
1171         case IDA_BUTTON_SUN:
1172         {
1173
1174                 if (!(__pAlarm->GetRepeatEverySundayFlag()))
1175                 {
1176                         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_FOCUS_BG);
1177                         pDayFocusBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_SUN_FOCUS_BG);
1178
1179                         __pAlarm->SetRepeatedEverySunday(true);
1180                 }
1181                 else
1182                 {
1183                         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_BG);
1184                         pDayFocusBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_SUN_BG);
1185
1186                         __pAlarm->SetRepeatedEverySunday(false);
1187                 }
1188
1189                 __pBtnDaySun->SetNormalBackgroundBitmap(*pDayNormalBitmap);
1190                 __pBtnDaySun->SetNormalBitmap(Point(0,0), *pDayFocusBitmap);
1191
1192                 if (pDayNormalBitmap != null)
1193                 {
1194                         delete pDayNormalBitmap;
1195                         pDayNormalBitmap = null;
1196                 }
1197
1198                 if (pDayFocusBitmap != null)
1199                 {
1200                         delete pDayFocusBitmap;
1201                         pDayFocusBitmap = null;
1202                 }
1203
1204         }
1205         break;
1206
1207         case IDA_BUTTON_MON:
1208         {
1209
1210                 if (!(__pAlarm->GetRepeatEveryMondayFlag()))
1211                 {
1212                         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_FOCUS_BG);
1213                         pDayFocusBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_MON_FOCUS_BG);
1214
1215                         __pAlarm->SetRepeatedEveryMonday(true);
1216                 }
1217                 else
1218                 {
1219                         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_BG);
1220                         pDayFocusBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_MON_BG);
1221
1222                         __pAlarm->SetRepeatedEveryMonday(false);
1223                 }
1224
1225                 __pBtnDayMon->SetNormalBackgroundBitmap(*pDayNormalBitmap);
1226                 __pBtnDayMon->SetNormalBitmap(Point(0,0), *pDayFocusBitmap);
1227
1228                 if (pDayNormalBitmap != null)
1229                 {
1230                         delete pDayNormalBitmap;
1231                         pDayNormalBitmap = null;
1232                 }
1233
1234                 if (pDayFocusBitmap != null)
1235                 {
1236                         delete pDayFocusBitmap;
1237                         pDayFocusBitmap = null;
1238                 }
1239         }
1240         break;
1241
1242         case IDA_BUTTON_TUE:
1243         {
1244
1245                 if (!(__pAlarm->GetRepeatEveryTuesdayFlag()))
1246                 {
1247                         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_FOCUS_BG);
1248                         pDayFocusBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_TUE_FOCUS_BG);
1249
1250                         __pAlarm->SetRepeatedEveryTuesday(true);
1251                 }
1252                 else
1253                 {
1254                         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_BG);
1255                         pDayFocusBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_TUE_BG);
1256
1257                         __pAlarm->SetRepeatedEveryTuesday(false);
1258                 }
1259
1260                 __pBtnDayTue->SetNormalBackgroundBitmap(*pDayNormalBitmap);
1261                 __pBtnDayTue->SetNormalBitmap(Point(0,0), *pDayFocusBitmap);
1262
1263                 if (pDayNormalBitmap != null)
1264                 {
1265                         delete pDayNormalBitmap;
1266                         pDayNormalBitmap = null;
1267                 }
1268
1269                 if (pDayFocusBitmap != null)
1270                 {
1271                         delete pDayFocusBitmap;
1272                         pDayFocusBitmap = null;
1273                 }
1274
1275         }
1276         break;
1277
1278         case IDA_BUTTON_WED:
1279         {
1280
1281                 if (!(__pAlarm->GetRepeatEveryWednesdayFlag()))
1282                 {
1283                         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_FOCUS_BG);
1284                         pDayFocusBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_WED_FOCUS_BG);
1285
1286                         __pAlarm->SetRepeatedEveryWednesday(true);
1287                 }
1288                 else
1289                 {
1290                         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_BG);
1291                         pDayFocusBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_WED_BG);
1292
1293                         __pAlarm->SetRepeatedEveryWednesday(false);
1294                 }
1295
1296                 __pBtnDayWed->SetNormalBackgroundBitmap(*pDayNormalBitmap);
1297                 __pBtnDayWed->SetNormalBitmap(Point(0,0), *pDayFocusBitmap);
1298
1299                 if (pDayNormalBitmap != null)
1300                 {
1301                         delete pDayNormalBitmap;
1302                         pDayNormalBitmap = null;
1303                 }
1304
1305                 if (pDayFocusBitmap != null)
1306                 {
1307                         delete pDayFocusBitmap;
1308                         pDayFocusBitmap = null;
1309                 }
1310
1311         }
1312         break;
1313
1314         case IDA_BUTTON_THU:
1315         {
1316
1317                 if (!(__pAlarm->GetRepeatEveryThursdayFlag()))
1318                 {
1319                         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_FOCUS_BG);
1320                         pDayFocusBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_THU_FOCUS_BG);
1321
1322                         __pAlarm->SetRepeatedEveryThursday(true);
1323                 }
1324                 else
1325                 {
1326                         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_BG);
1327                         pDayFocusBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_THU_BG);
1328
1329                         __pAlarm->SetRepeatedEveryThursday(false);
1330                 }
1331
1332                 __pBtnDayThu->SetNormalBackgroundBitmap(*pDayNormalBitmap);
1333                 __pBtnDayThu->SetNormalBitmap(Point(0,0), *pDayFocusBitmap);
1334
1335                 if (pDayNormalBitmap != null)
1336                 {
1337                         delete pDayNormalBitmap;
1338                         pDayNormalBitmap = null;
1339                 }
1340
1341                 if (pDayFocusBitmap != null)
1342                 {
1343                         delete pDayFocusBitmap;
1344                         pDayFocusBitmap = null;
1345                 }
1346
1347         }
1348         break;
1349
1350         case IDA_BUTTON_FRI:
1351         {
1352
1353                 if (!(__pAlarm->GetRepeatEveryFridayFlag()))
1354                 {
1355                         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_FOCUS_BG);
1356                         pDayFocusBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_FRI_FOCUS_BG);
1357
1358                         __pAlarm->SetRepeatedEveryFriday(true);
1359                 }
1360                 else
1361                 {
1362                         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_BG);
1363                         pDayFocusBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_FRI_BG);
1364
1365                         __pAlarm->SetRepeatedEveryFriday(false);
1366                 }
1367
1368                 __pBtnDayFri->SetNormalBackgroundBitmap(*pDayNormalBitmap);
1369                 __pBtnDayFri->SetNormalBitmap(Point(0,0), *pDayFocusBitmap);
1370
1371                 if (pDayNormalBitmap != null)
1372                 {
1373                         delete pDayNormalBitmap;
1374                         pDayNormalBitmap = null;
1375                 }
1376
1377                 if (pDayFocusBitmap != null)
1378                 {
1379                         delete pDayFocusBitmap;
1380                         pDayFocusBitmap = null;
1381                 }
1382
1383         }
1384         break;
1385
1386         case IDA_BUTTON_SAT:
1387         {
1388
1389                 if (!(__pAlarm->GetRepeatEverySaturdayFlag()))
1390                 {
1391                         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_FOCUS_BG);
1392                         pDayFocusBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_SAT_FOCUS_BG);
1393
1394                         __pAlarm->SetRepeatedEverySaturday(true);
1395                 }
1396                 else
1397                 {
1398                         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_BG);
1399                         pDayFocusBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_SAT_BG);
1400
1401                         __pAlarm->SetRepeatedEverySaturday(false);
1402                 }
1403
1404                 __pBtnDaySat->SetNormalBackgroundBitmap(*pDayNormalBitmap);
1405                 __pBtnDaySat->SetNormalBitmap(Point(0,0), *pDayFocusBitmap);
1406
1407                 if (pDayNormalBitmap != null)
1408                 {
1409                         delete pDayNormalBitmap;
1410                         pDayNormalBitmap = null;
1411                 }
1412
1413                 if (pDayFocusBitmap != null)
1414                 {
1415                         delete pDayFocusBitmap;
1416                         pDayFocusBitmap = null;
1417                 }
1418
1419         }
1420         break;
1421
1422         case IDA_BUTTON_HOURS:
1423         {
1424
1425                 Canvas* pCanvas = null;
1426                 Bitmap* pbgBitmap = null;
1427                 Bitmap* pFinalBitmap = null;
1428                 Bitmap* pBgNormalBitmap = null;
1429                 Bitmap* pbgFocusBitmap = null;
1430                 Bitmap* pFinalBitmapFocused = null;
1431                 Canvas* pCanvasFocused = null;
1432                 int canvasWidth = 276;
1433                 int canvasHeight = 236;
1434
1435                 if (__pBtnHourDisplay == null || __pBtnMinDisplay == null)
1436                 {
1437                         return;
1438                 }
1439
1440                 pBgNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_NORMAL_BG);
1441                 pbgBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_BG);
1442
1443                 pCanvas = new (std::nothrow) Canvas();
1444                 pCanvas->Construct(Rectangle(0,0,canvasWidth,canvasHeight));
1445                 pCanvas->DrawBitmap(Point(0,0),*pBgNormalBitmap);
1446                 pCanvas->DrawBitmap(Point(0,0),*pbgBitmap);
1447
1448                 if (pBgNormalBitmap != null)
1449                 {
1450                         delete pBgNormalBitmap;
1451                         pBgNormalBitmap = null;
1452                 }
1453
1454                 if (pbgBitmap != null)
1455                 {
1456                         delete pbgBitmap;
1457                         pbgBitmap = null;
1458                 }
1459
1460                 pFinalBitmap = new (std::nothrow) Bitmap();
1461
1462                 if ( pFinalBitmap != NULL)
1463                 {
1464                         pFinalBitmap->Construct(*pCanvas,Rectangle(0,0,canvasWidth,canvasHeight));
1465                         delete pCanvas;
1466                 }
1467                 pbgFocusBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_FOCUS_BG);
1468                 pbgBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_BG);
1469
1470                 pCanvasFocused = new (std::nothrow) Canvas();
1471                 pCanvasFocused->Construct(Rectangle(0,0,canvasWidth,canvasHeight));
1472                 pCanvasFocused->DrawBitmap(Point(0,0),*pbgFocusBitmap);
1473                 pCanvasFocused->DrawBitmap(Point(0,0),*pbgBitmap);
1474
1475                 if (pbgFocusBitmap != null)
1476                 {
1477                         delete pbgFocusBitmap;
1478                         pbgFocusBitmap = null;
1479                 }
1480
1481                 if (pbgBitmap != null)
1482                 {
1483                         delete pbgBitmap;
1484                         pbgBitmap = null;
1485                 }
1486
1487                 pFinalBitmapFocused = new (std::nothrow) Bitmap();
1488
1489                 if ( pFinalBitmapFocused != null)
1490                 {
1491                         pFinalBitmapFocused->Construct(*pCanvasFocused,Rectangle(0,0,canvasWidth,canvasHeight));
1492                         delete pCanvasFocused;
1493                 }
1494
1495                 __pBtnMinDisplay->SetNormalBackgroundBitmap(*pFinalBitmap);
1496                 __pBtnMinDisplay->SetPressedBackgroundBitmap(*pFinalBitmap);
1497                 __pBtnHourDisplay->SetNormalBackgroundBitmap(*pFinalBitmapFocused);
1498                 __pBtnHourDisplay->SetPressedBackgroundBitmap(*pFinalBitmapFocused);
1499                 __pBtnHourDisplay->Invalidate(true);
1500                 __pBtnMinDisplay->Invalidate(true);
1501
1502                 if (&source == __pBtnHourDisplay)
1503                 {
1504                         ShowHourKeypad();
1505                 }
1506
1507                 if (pFinalBitmap != null)
1508                 {
1509                         delete pFinalBitmap;
1510                         pFinalBitmap = null;
1511                 }
1512
1513                 if (pFinalBitmapFocused != null)
1514                 {
1515                         delete pFinalBitmapFocused;
1516                         pFinalBitmapFocused = null;
1517                 }
1518
1519                 if(isHourClicked == true)
1520                 {
1521                         return;
1522                 }
1523
1524                 __hourText.Clear();
1525                 if (__pBtnHourDisplay->GetText().GetLength() == 1)
1526                 {
1527                         __hourText.Append("0");
1528                         __hourText.Append(__pBtnHourDisplay->GetText());
1529                 }
1530
1531                 isHourClicked = true;
1532
1533
1534         }
1535         break;
1536
1537         case IDA_BUTTON_MINS:
1538         {
1539                 Canvas* pCanvas = null;
1540                 Bitmap* pbgBitmap = null;
1541                 Bitmap* pFinalBitmap = null;
1542                 Bitmap* pBgNormalBitmap = null;
1543                 Bitmap* pbgFocusBitmap = null;
1544                 Bitmap* pFinalBitmapFocused = null;
1545                 Canvas* pCanvasFocused = null;
1546                 int canvasWidth = 276;
1547                 int canvasHeight = 236;
1548
1549                 if (__pBtnHourDisplay == null || __pBtnMinDisplay == null)
1550                 {
1551                         return;
1552                 }
1553
1554                 pBgNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_NORMAL_BG);
1555                 pbgBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_BG);
1556
1557                 pCanvas = new (std::nothrow) Canvas();
1558                 pCanvas->Construct(Rectangle(0,0,canvasWidth,canvasHeight));
1559                 pCanvas->DrawBitmap(Point(0,0),*pBgNormalBitmap);
1560                 pCanvas->DrawBitmap(Point(0,0),*pbgBitmap);
1561
1562                 if (pBgNormalBitmap != null)
1563                 {
1564                         delete pBgNormalBitmap;
1565                         pBgNormalBitmap = null;
1566                 }
1567
1568                 if (pbgBitmap != null)
1569                 {
1570                         delete pbgBitmap;
1571                         pbgBitmap = null;
1572                 }
1573
1574                 pFinalBitmap = new (std::nothrow) Bitmap();
1575
1576                 if ( pFinalBitmap != NULL)
1577                 {
1578                         pFinalBitmap->Construct(*pCanvas,Rectangle(0,0,canvasWidth,canvasHeight));
1579                         delete pCanvas;
1580                 }
1581
1582                 pbgFocusBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_FOCUS_BG);
1583                 pbgBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_BG);
1584
1585                 pCanvasFocused = new (std::nothrow) Canvas();
1586                 pCanvasFocused->Construct(Rectangle(0,0,canvasWidth,canvasHeight));
1587                 pCanvasFocused->DrawBitmap(Point(0,0),*pbgFocusBitmap);
1588                 pCanvasFocused->DrawBitmap(Point(0,0),*pbgBitmap);
1589
1590                 if (pbgFocusBitmap != null)
1591                 {
1592                         delete pbgFocusBitmap;
1593                         pbgFocusBitmap = null;
1594                 }
1595
1596                 if (pbgBitmap != null)
1597                 {
1598                         delete pbgBitmap;
1599                         pbgBitmap = null;
1600                 }
1601
1602                 pFinalBitmapFocused = new (std::nothrow) Bitmap();
1603
1604                 if ( pFinalBitmapFocused != null)
1605                 {
1606                         pFinalBitmapFocused->Construct(*pCanvasFocused,Rectangle(0,0,canvasWidth,canvasHeight));
1607                         delete pCanvasFocused;
1608                 }
1609
1610                 if (is24HourFormat == false && __pBtnHourDisplay->GetText().CompareTo(L"0") == 0 && isHourClicked == true)
1611                 {
1612                         __pBtnHourDisplay->SetText(L"12");
1613                 }
1614
1615                 __pBtnHourDisplay->SetNormalBackgroundBitmap(*pFinalBitmap);
1616                 __pBtnHourDisplay->SetPressedBackgroundBitmap(*pFinalBitmap);
1617                 __pBtnMinDisplay->SetNormalBackgroundBitmap(*pFinalBitmapFocused);
1618                 __pBtnMinDisplay->SetPressedBackgroundBitmap(*pFinalBitmapFocused);
1619
1620                 __pBtnHourDisplay->Invalidate(true);
1621                 __pBtnMinDisplay->Invalidate(true);
1622
1623                 if (__pBtnMinDisplay != null && &source == __pBtnMinDisplay)
1624                 {
1625                         ShowMinKeypad();
1626                 }
1627
1628                 if (pFinalBitmap != null)
1629                 {
1630                         delete pFinalBitmap;
1631                         pFinalBitmap = null;
1632                 }
1633                 if (pFinalBitmapFocused != null)
1634                 {
1635                         delete pFinalBitmapFocused;
1636                         pFinalBitmapFocused = null;
1637                 }
1638
1639
1640                 if(isHourClicked == false)
1641                 {
1642                         return;
1643                 }
1644
1645                 __hourText.Clear();
1646                 if (__pBtnMinDisplay->GetText().GetLength() == 1)
1647                 {
1648                         __hourText.Append("0");
1649                         __hourText.Append(__pBtnMinDisplay->GetText());
1650                 }
1651                 isHourClicked = false;
1652         }
1653         break;
1654
1655         default:
1656                 break;
1657         }
1658 }
1659
1660 void
1661 AlarmEditorForm::OnAdjustmentValueChanged(const Control& source, int adjustment)
1662 {
1663         AppLogDebug("ENTER %d",adjustment);
1664         result r = E_SUCCESS;
1665         __sliderValues.RemoveAll();
1666         __sliderValues.Push(adjustment);
1667
1668         SettingInfo::RemoveSettingEventListener(*this);
1669         r = SettingInfo::SetValue(L"http://tizen.org/setting/sound.media.volume", adjustment);
1670         SettingInfo::AddSettingEventListener(*this);
1671
1672         if(__pSlider)
1673         {
1674                 __pSlider->SetFocus();
1675                 __pSlider->Invalidate(false);
1676         }
1677
1678         if(__sliderValues.GetCount() == 1)
1679         {
1680                 SendUserEvent(10000, null);
1681         }
1682
1683         __sliderValue = adjustment;
1684         AppLogDebug("EXIT");
1685 }
1686
1687 void
1688 AlarmEditorForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
1689 {
1690         AppLog("AlarmEditorForm::OnSceneActivatedN");
1691         result r = E_SUCCESS;
1692         bool flag = false;
1693         int counter = 0;
1694         int count = 0;
1695         int alarmCount = 0;
1696         int volume = 0;
1697         int timeFormat = 12;
1698         ArrayList alarmList;
1699         String title ;
1700         String alarmTitle ;
1701         DateTime currentTime;
1702         String durationValue;
1703         AlarmPresentationModel* pAlarmPresentationModel = AlarmPresentationModel::GetInstance();
1704         DataServiceProvider* pDataServiceProvider = DataServiceProvider::GetInstance();
1705         Bitmap* pToggleBtnPMBG = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_TOGGLE_PM_BG);
1706         Bitmap* pToggleBtnAMBG = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_TOGGLE_AM_BG);
1707         Bitmap* pDayNormalBitmap = null;
1708         Bitmap* pNormalBitmap = null;
1709         Bitmap* pFocusBitmap = null;
1710
1711         if (previousSceneId != IDSCN_EDIT_SNOOZE && previousSceneId != IDSCN_ALARM_RINGING && previousSceneId != IDSCN_ALARM_RINGING_LOCK && previousSceneId != IDSCN_TIMER_RINGING && previousSceneId != IDSCN_TIMER_RINGING_LOCK)
1712         {
1713                 String alarmTone;
1714                 String alarmPath;
1715                 __pAlarm = new (std::nothrow) AlarmData();
1716                 //alarmTone = UiApp::GetInstance()->GetAppRootPath() + L"/data/04-Kyun.mp3";
1717                 __pAlarm->SetRingTone(__audioFilePath);
1718         }
1719
1720         if (previousSceneId == IDSCN_ALARM_LIST && pArgs != null)
1721         {
1722                 AppLog("Coming from AlarmList");
1723                 String hour, min;
1724                 int alarmTimeHour, alarmTimeMin;
1725
1726                 if (__pAlarm != null)
1727                 {
1728                         delete __pAlarm;
1729                         __pAlarm = null;
1730                 }
1731
1732                 __pAlarm = dynamic_cast<AlarmData*>(pArgs->GetAt(0));
1733
1734                 if (__pAlarm == null)
1735                 {
1736                         return;
1737                 }
1738
1739                 __pOldAlarm = new AlarmData(*__pAlarm);
1740
1741                 volume = __pAlarm->GetRingVolume();
1742                 AppLog("volume: %d",volume);
1743
1744                 alarmTimeHour = __pAlarm->GetAlarmTime().GetHour();
1745                 alarmTimeMin = __pAlarm->GetAlarmTime().GetMinute();
1746
1747                 if(is24HourFormat == false)
1748                 {
1749                         if (alarmTimeHour < timeFormat)
1750                         {
1751                                 __defaultToggleValue = CommonUtil::GetString(L"IDS_COM_BODY_AM");
1752                                 __pBtnToggle->SetNormalBackgroundBitmap(*pToggleBtnAMBG);
1753                                 __pBtnToggle->SetPressedBackgroundBitmap(*pToggleBtnAMBG);
1754                         }
1755                         else
1756                         {
1757                                 alarmTimeHour = alarmTimeHour - timeFormat;
1758                                 __defaultToggleValue = CommonUtil::GetString(L"IDS_COM_POP_PM");
1759                                 __pBtnToggle->SetNormalBackgroundBitmap(*pToggleBtnPMBG);
1760                                 __pBtnToggle->SetPressedBackgroundBitmap(*pToggleBtnPMBG);
1761                         }
1762                 }
1763                 else
1764                 {
1765                         __pBtnToggle->SetShowState(false);
1766                         __pLabelAm->SetShowState(false);
1767                         __pLabelPm->SetShowState(false);
1768                 }
1769
1770                 if(alarmTimeHour == 0 && is24HourFormat == false)
1771                 {
1772                         alarmTimeHour = 12;
1773                 }
1774
1775                 if ( alarmTimeHour < 10)
1776                 {
1777                         hour.Append(0);
1778                 }
1779
1780                 if (alarmTimeMin < 10)
1781                 {
1782                         min.Append(0);
1783                 }
1784
1785                 hour.Append(alarmTimeHour);
1786                 min.Append(alarmTimeMin);
1787
1788                 __pBtnHourDisplay->SetText(hour);
1789                 __pBtnMinDisplay->SetText(min);
1790                 __pBtnHourDisplay->Invalidate(false);
1791                 __pBtnMinDisplay->Invalidate(false);
1792
1793                 __pEditField->SetText(__pAlarm->GetAlarmName());
1794                 __pSlider->SetValue(volume);
1795
1796                 __pLabelTitle->SetText(__pAlarm->GetAlarmName());
1797                 __pLabelTitle->Invalidate(false);
1798
1799                 pNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_BG);
1800                 pFocusBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_FOCUS_BG);
1801
1802                 if (__pAlarm->GetRepeatEverySundayFlag())
1803                 {
1804                         __pBtnDaySun->SetNormalBackgroundBitmap(*pFocusBitmap);
1805                         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_SUN_FOCUS_BG);
1806                 }
1807                 else
1808                 {
1809                         __pBtnDaySun->SetNormalBackgroundBitmap(*pNormalBitmap);
1810                         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_SUN_BG);
1811                 }
1812
1813                 __pBtnDaySun->SetNormalBitmap(Point(0,0), *pDayNormalBitmap);
1814
1815                 if (pDayNormalBitmap != null)
1816                 {
1817                         delete pDayNormalBitmap;
1818                         pDayNormalBitmap = null;
1819                 }
1820
1821                 if (__pAlarm->GetRepeatEveryMondayFlag())
1822                 {
1823                         __pBtnDayMon->SetNormalBackgroundBitmap(*pFocusBitmap);
1824                         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_MON_FOCUS_BG);
1825                 }
1826                 else
1827                 {
1828                         __pBtnDayMon->SetNormalBackgroundBitmap(*pNormalBitmap);
1829                         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_MON_BG);
1830                 }
1831
1832                 __pBtnDayMon->SetNormalBitmap(Point(0,0), *pDayNormalBitmap);
1833
1834                 if (pDayNormalBitmap != null)
1835                 {
1836                         delete pDayNormalBitmap;
1837                         pDayNormalBitmap = null;
1838                 }
1839
1840                 if (__pAlarm->GetRepeatEveryTuesdayFlag())
1841                 {
1842                         __pBtnDayTue->SetNormalBackgroundBitmap(*pFocusBitmap);
1843                         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_TUE_FOCUS_BG);
1844                 }
1845                 else
1846                 {
1847                         __pBtnDayTue->SetNormalBackgroundBitmap(*pNormalBitmap);
1848                         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_TUE_BG);
1849                 }
1850
1851                 __pBtnDayTue->SetNormalBitmap(Point(0,0), *pDayNormalBitmap);
1852
1853                 if (pDayNormalBitmap != null)
1854                 {
1855                         delete pDayNormalBitmap;
1856                         pDayNormalBitmap = null;
1857                 }
1858
1859                 if (__pAlarm->GetRepeatEveryWednesdayFlag())
1860                 {
1861                         __pBtnDayWed->SetNormalBackgroundBitmap(*pFocusBitmap);
1862                         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_WED_FOCUS_BG);
1863                 }
1864                 else
1865                 {
1866                         __pBtnDayWed->SetNormalBackgroundBitmap(*pNormalBitmap);
1867                         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_WED_BG);
1868                 }
1869
1870                 __pBtnDayWed->SetNormalBitmap(Point(0,0), *pDayNormalBitmap);
1871
1872                 if (pDayNormalBitmap != null)
1873                 {
1874                         delete pDayNormalBitmap;
1875                         pDayNormalBitmap = null;
1876                 }
1877
1878                 if (__pAlarm->GetRepeatEveryThursdayFlag())
1879                 {
1880                         __pBtnDayThu->SetNormalBackgroundBitmap(*pFocusBitmap);
1881                         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_THU_FOCUS_BG);
1882                 }
1883                 else
1884                 {
1885                         __pBtnDayThu->SetNormalBackgroundBitmap(*pNormalBitmap);
1886                         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_THU_BG);
1887                 }
1888
1889                 __pBtnDayThu->SetNormalBitmap(Point(0,0), *pDayNormalBitmap);
1890
1891                 if (pDayNormalBitmap != null)
1892                 {
1893                         delete pDayNormalBitmap;
1894                         pDayNormalBitmap = null;
1895                 }
1896
1897                 if (__pAlarm->GetRepeatEveryFridayFlag())
1898                 {
1899                         __pBtnDayFri->SetNormalBackgroundBitmap(*pFocusBitmap);
1900                         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_FRI_FOCUS_BG);
1901                 }
1902                 else
1903                 {
1904                         __pBtnDayFri->SetNormalBackgroundBitmap(*pNormalBitmap);
1905                         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_FRI_BG);
1906                 }
1907
1908                 __pBtnDayFri->SetNormalBitmap(Point(0,0), *pDayNormalBitmap);
1909
1910                 if (pDayNormalBitmap != null)
1911                 {
1912                         delete pDayNormalBitmap;
1913                         pDayNormalBitmap = null;
1914                 }
1915
1916                 if (__pAlarm->GetRepeatEverySaturdayFlag())
1917                 {
1918                         __pBtnDaySat->SetNormalBackgroundBitmap(*pFocusBitmap);
1919                         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_SAT_FOCUS_BG);
1920                 }
1921                 else
1922                 {
1923                         __pBtnDaySat->SetNormalBackgroundBitmap(*pNormalBitmap);
1924                         pDayNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_DAYS_SAT_BG);
1925                 }
1926
1927                 __pBtnDaySat->SetNormalBitmap(Point(0,0), *pDayNormalBitmap);
1928
1929                 if (pDayNormalBitmap != null)
1930                 {
1931                         delete pDayNormalBitmap;
1932                         pDayNormalBitmap = null;
1933                 }
1934
1935                 if (pFocusBitmap != null)
1936                 {
1937                         delete pFocusBitmap;
1938                         pFocusBitmap = null;
1939                 }
1940
1941                 if (pNormalBitmap != null)
1942                 {
1943                         delete pNormalBitmap;
1944                         pNormalBitmap = null;
1945                 }
1946
1947                 if (__pAlarm->GetRingType() == 0)
1948                 {
1949                         __selectedIndex = 1;
1950                 }
1951
1952                 if (__pAlarm->GetRingType() == 1)
1953                 {
1954                         __selectedIndex = 2;
1955                 }
1956
1957                 if (__pAlarm->GetRingType() == 2)
1958                 {
1959                         __selectedIndex = 3;
1960                 }
1961
1962                 __typeName = __pAlarm->GetRingType();
1963
1964                 if (__pDuration != null)
1965                 {
1966                         delete __pDuration;
1967                         __pDuration = null;
1968                 }
1969
1970                 if (__pRepeat != null)
1971                 {
1972                         delete __pRepeat;
1973                         __pRepeat = null;
1974                 }
1975
1976
1977                 __pDuration = new (std::nothrow) Integer(__pAlarm->GetSnoozeDuration());
1978                 __pRepeat = new (std::nothrow) Integer(__pAlarm->GetSnoozeRepeat());
1979
1980                 __snoozeDurationValue.Clear();
1981
1982                 if (__pDuration->ToInt() == 3)
1983                 {
1984                         __snoozeDurationValue.Append(CommonUtil::GetString(L"IDS_ALM_BODY_3MINS"));
1985                 }
1986                 else if (__pDuration->ToInt() == 5)
1987                 {
1988                         __snoozeDurationValue.Append(CommonUtil::GetString(L"IDS_ALM_BODY_5MINS"));
1989                 }
1990                 else
1991                 {
1992                         __snoozeDurationValue.Append(CommonUtil::GetString(L"IDS_ALM_BODY_10MINS"));
1993                 }
1994
1995                 __snoozeDurationValue.Append(L", ");
1996                 durationValue.Format(25, CommonUtil::GetString(L"IDS_CLOCK_BODY_PD_TIMES").GetPointer(), __pRepeat->ToInt());
1997                 __snoozeDurationValue.Append(durationValue);
1998
1999         }
2000         else if (previousSceneId == IDSCN_ALARM_LIST && pArgs == null)
2001         {
2002                 String hourValue= L"";
2003                 String minValue ;
2004                 int hour = 0;
2005                 int numberSelectorHour, numberSelectorMin;
2006
2007                 pDataServiceProvider->GetCurrentDateTime(currentTime);
2008
2009                 if (is24HourFormat == false)
2010                 {
2011                         if (currentTime.GetHour() > timeFormat)
2012                         {
2013                                 hour = currentTime.GetHour() - timeFormat;
2014                         }
2015
2016                         else
2017                         {
2018                                 hour = currentTime.GetHour();
2019                         }
2020                 }
2021                 else
2022                 {
2023                         hour = currentTime.GetHour();
2024                         __pBtnToggle->SetShowState(false);
2025                         __pLabelAm->SetShowState(false);
2026                         __pLabelPm->SetShowState(false);
2027                 }
2028
2029                 if(hour == 0 && is24HourFormat == false)
2030                 {
2031                         hour = 12;
2032                 }
2033
2034                 if (hour < 10)
2035                 {
2036                         hourValue.Append(0);
2037                 }
2038
2039                 if (currentTime.GetMinute() < 10)
2040                 {
2041                         minValue.Append(0);
2042                 }
2043
2044                 hourValue.Append(hour);
2045                 minValue.Append(currentTime.GetMinute());
2046
2047                 if (__pDuration != null)
2048                 {
2049                         delete __pDuration;
2050                         __pDuration = null;
2051                 }
2052
2053                 if (__pRepeat != null)
2054                 {
2055                         delete __pRepeat;
2056                         __pRepeat = null;
2057                 }
2058
2059                 __pDuration = new (std::nothrow) Integer(5);
2060                 __pRepeat = new (std::nothrow) Integer(3);
2061
2062                 if (is24HourFormat == false)
2063                 {
2064                         if (currentTime.GetHour() < timeFormat)
2065                         {
2066                                 __defaultToggleValue = CommonUtil::GetString(L"IDS_COM_BODY_AM");
2067                                 __pBtnToggle->SetNormalBackgroundBitmap(*pToggleBtnAMBG);
2068                                 __pBtnToggle->SetPressedBackgroundBitmap(*pToggleBtnAMBG);
2069                         }
2070                         else if (currentTime.GetHour() >= timeFormat)
2071                         {
2072                                 __defaultToggleValue = CommonUtil::GetString(L"IDS_COM_POP_PM");
2073                                 __pBtnToggle->SetNormalBackgroundBitmap(*pToggleBtnPMBG);
2074                                 __pBtnToggle->SetPressedBackgroundBitmap(*pToggleBtnPMBG);
2075                         }
2076                 }
2077
2078                 __snoozeDurationValue.Clear();
2079
2080                 if (__pDuration->ToInt() == 3)
2081                 {
2082                         __snoozeDurationValue.Append(CommonUtil::GetString(L"IDS_ALM_BODY_3MINS"));
2083                 }
2084                 else if (__pDuration->ToInt() == 5)
2085                 {
2086                         __snoozeDurationValue.Append(CommonUtil::GetString(L"IDS_ALM_BODY_5MINS"));
2087                 }
2088                 else
2089                 {
2090                         __snoozeDurationValue.Append(CommonUtil::GetString(L"IDS_ALM_BODY_10MINS"));
2091                 }
2092
2093                 __snoozeDurationValue.Append(L", ");
2094                 durationValue.Format(25, CommonUtil::GetString(L"IDS_CLOCK_BODY_PD_TIMES").GetPointer(), __pRepeat->ToInt());
2095                 __snoozeDurationValue.Append(durationValue);
2096
2097
2098                 Integer::Parse(hourValue, numberSelectorHour);
2099                 Integer::Parse(minValue, numberSelectorMin);
2100                 __pBtnHourDisplay->SetText(hourValue);
2101                 __pBtnMinDisplay->SetText(minValue);
2102                 __pBtnHourDisplay->Invalidate(false);
2103                 __pBtnMinDisplay->Invalidate(false);
2104                 __pAlarm->SetSnoozeOn(__isSnoozeOn);
2105
2106         }
2107         else
2108         {
2109                 AppLog("the control frm myfiles comes here");
2110                 if (pArgs != null)
2111                 {
2112
2113                         if (__pDuration != null)
2114                         {
2115                                 delete __pDuration;
2116                                 __pDuration = null;
2117                         }
2118
2119                         if (__pRepeat != null)
2120                         {
2121                                 delete __pRepeat;
2122                                 __pRepeat = null;
2123                         }
2124
2125                         __pDuration = dynamic_cast<Integer*>(pArgs->GetAt(0));
2126
2127                         if (__pDuration == null)
2128                         {
2129                                 return;
2130                         }
2131
2132                         __pRepeat = dynamic_cast<Integer*>(pArgs->GetAt(1));
2133
2134                         if (__pRepeat == null)
2135                         {
2136                                 return;
2137                         }
2138                         __snoozeDurationValue.Clear();
2139
2140                         if (__pDuration->ToInt() == 3)
2141                         {
2142                                 __snoozeDurationValue.Append(CommonUtil::GetString(L"IDS_ALM_BODY_3MINS"));
2143                         }
2144                         else if (__pDuration->ToInt() == 5)
2145                         {
2146                                 __snoozeDurationValue.Append(CommonUtil::GetString(L"IDS_ALM_BODY_5MINS"));
2147                         }
2148                         else
2149                         {
2150                                 __snoozeDurationValue.Append(CommonUtil::GetString(L"IDS_ALM_BODY_10MINS"));
2151                         }
2152
2153                         __snoozeDurationValue.Append(L", ");
2154                         durationValue.Format(25, CommonUtil::GetString(L"IDS_CLOCK_BODY_PD_TIMES").GetPointer(), __pRepeat->ToInt());
2155                         __snoozeDurationValue.Append(durationValue);
2156                         __pAlarm->SetSnoozeDuration(__pDuration->ToInt());
2157                         __pAlarm->SetSnoozeRepeat(__pRepeat->ToInt());
2158
2159                 }
2160                 __pGroupedListView->UpdateList();
2161         }
2162
2163         r = pAlarmPresentationModel->GetAlarmCount(alarmCount);   // to get count of existing folders
2164
2165         r = pAlarmPresentationModel->GetAlarm(0, alarmCount, alarmList);   // to get list of existing folders
2166
2167         if (previousSceneId != IDSCN_TIMER_RINGING && previousSceneId != IDSCN_ALARM_RINGING)
2168         {
2169                 if (pArgs == null)
2170                 {
2171                         while (true)              // to provide user with unique alarm title when he creates a new (std::nothrow) alarm
2172                         {                         // to generate alarm with default name of type alarmN
2173                                 flag = false ;
2174                                 title = L"";
2175                                 count = 0;
2176                                 counter++;
2177                                 title.Append(CommonUtil::GetString(L"IDS_COM_BODY_ALARM"));
2178                                 title.Append(counter);
2179
2180                                 for (count = 0; count < alarmCount; count++)
2181                                 {
2182                                         AlarmData* pAlarm = dynamic_cast<AlarmData*>(alarmList.GetAt(count));
2183                                         alarmTitle = L"";
2184                                         alarmTitle = pAlarm->GetAlarmName();
2185
2186                                         if (title.Equals(alarmTitle,false))
2187                                         {
2188                                                 flag = true;    // if flag is true alarm title already exists
2189                                                 break;          // break from for loop
2190                                         }
2191
2192                                 }    // end of for loop
2193
2194                                 if (!flag)
2195                                 {
2196                                         __pEditField->SetText(title);      // if flag is false alarm title is unique
2197                                         __pLabelTitle->SetText(title);
2198                                         break;                               // break from while loop
2199                                 }
2200
2201                         }  // end of while loop
2202                 }
2203         }
2204
2205         if (__pListView != null)
2206         {
2207                 if (previousSceneId == IDSCN_EDIT_SNOOZE)
2208                 {
2209                         __pListView->RefreshList(0, LIST_REFRESH_TYPE_ITEM_MODIFY);
2210                         __pListView->RefreshList(1, LIST_REFRESH_TYPE_ITEM_MODIFY);
2211                 }
2212                 else
2213                 {
2214                         __pListView->UpdateList();
2215                 }
2216         }
2217
2218
2219         if (__pGroupedListView != null)
2220         {
2221                 __pGroupedListView->UpdateList();
2222                 __pGroupedListView->SetItemEnabled(0,-1,false);
2223         }
2224
2225         RearrangeControls();
2226
2227         if (__pListView != null)
2228         {
2229                 __pListView->SetItemChecked(0,__pAlarm->GetSnoozeOn());
2230         }
2231
2232         if (pToggleBtnPMBG != null)
2233         {
2234                 delete pToggleBtnPMBG;
2235                 pToggleBtnPMBG = null;
2236         }
2237
2238         if (pToggleBtnAMBG != null)
2239         {
2240                 delete pToggleBtnAMBG;
2241                 pToggleBtnAMBG = null;
2242         }
2243
2244         Invalidate(true);
2245         StartAudio();
2246 }
2247
2248 void
2249 AlarmEditorForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
2250 {
2251
2252         if (__pEditField != null)
2253         {
2254                 //if (nextSceneId != IDSCN_TIMER_RINGING && nextSceneId != IDSCN_ALARM_RINGING)
2255                 {
2256                         __pEditField->HideKeypad();
2257                 }
2258         }
2259
2260         //if (nextSceneId != IDSCN_TIMER_RINGING && nextSceneId != IDSCN_ALARM_RINGING)
2261         {
2262                 if (__pBtnHourDisplay->HasFocus())
2263                 {
2264                         HideHourKeypad();
2265                 }
2266                 else if (__pBtnMinDisplay->HasFocus())
2267                 {
2268                         HideMinKeypad();
2269                 }
2270         }
2271
2272         if (__player)
2273         {
2274                 __player->Stop();
2275                 __player->Close();
2276         }
2277
2278         GetHeader()->SetShowState(false);
2279         Invalidate(true);
2280
2281 }
2282
2283 void
2284 AlarmEditorForm::OnFormBackRequested(Controls::Form& source)
2285 {
2286         if(!__isAppControlCompleted)
2287         {
2288                 SendUserEvent(REQUEST_ID_TERMINATE, null);
2289         }
2290 }
2291
2292 void
2293 AlarmEditorForm::OnListViewItemStateChanged(ListView& listView, int index, int elementId, ListItemStatus status)
2294 {
2295         AppLog("AlarmEditorForm::OnListViewItemStateChanged");
2296         String repeatFlag = L"";
2297         ArrayList *pArgList = null;
2298         SceneManager* pSceneManager = SceneManager::GetInstance();
2299
2300         if (__pEditField != null)
2301         {
2302                 //__pEditField->HideKeypad();
2303         }
2304
2305         if (index == 0)
2306         {
2307                 if (status == LIST_ITEM_STATUS_UNCHECKED && __snoozeStatus == true)
2308                 {
2309                         __snoozeStatus = false;
2310                         __pAlarm->SetSnoozeOn(false);
2311                         __pListView->RefreshList(1,LIST_REFRESH_TYPE_ITEM_REMOVE);
2312                         __pListView->RefreshList(1,LIST_REFRESH_TYPE_ITEM_MODIFY);
2313                 }
2314                 else if(status == LIST_ITEM_STATUS_CHECKED && __snoozeStatus == false)
2315                 {
2316                         __snoozeStatus = true;
2317                         __pAlarm->SetSnoozeOn(true);
2318                         __pListView->RefreshList(1,LIST_REFRESH_TYPE_ITEM_ADD);
2319                         __pListView->RefreshList(1,LIST_REFRESH_TYPE_ITEM_MODIFY);
2320                 }
2321                 RearrangeControls();
2322         }
2323
2324         else if (index == 1)
2325         {
2326                 pArgList = new (std::nothrow) ArrayList();
2327
2328                 if (pArgList != null)
2329                 {
2330                         pArgList->Construct();
2331                         pArgList->Add(*__pAlarm);
2332                         AppLog("the duration is %d", __pAlarm->GetSnoozeDuration());
2333                 }
2334
2335                 if (pSceneManager != null)
2336                 {
2337                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_EDIT_SNOOZE), pArgList);
2338                 }
2339
2340                 __pListView->RefreshList(1, LIST_REFRESH_TYPE_ITEM_MODIFY);
2341
2342         }
2343
2344
2345         //__pListView->RefreshList(index, LIST_REFRESH_TYPE_ITEM_MODIFY);
2346         //__pListView->RefreshList(0, LIST_REFRESH_TYPE_ITEM_MODIFY);
2347
2348 }
2349
2350 GroupItem*
2351 AlarmEditorForm::CreateGroupItem(int groupIndex, int itemWidth)
2352 {
2353         result r = E_FAILURE;
2354         String text;
2355         GroupItem* pItem = null;
2356         Bitmap* pbgActive = null;
2357         AppResource* pAppResource = null;
2358         const Color ITEM_TEXT_COLOR = Color(92, 151, 187);
2359
2360         pItem = new (std::nothrow) GroupItem();
2361
2362         if (pItem == null)
2363         {
2364                 return null;
2365         }
2366
2367         r = pItem->Construct(Dimension(itemWidth, 0));
2368
2369         if (IsFailed(r))
2370         {
2371                 delete pItem;
2372                 return null;
2373         }
2374
2375         switch (groupIndex)
2376         {
2377         case 0:
2378         {
2379                 text = L"";
2380         }
2381         break;
2382
2383         case 1:
2384         {
2385                 text = L"";
2386         }
2387         break;
2388
2389         case 2:
2390         {
2391                 text = L"";
2392         }
2393         break;
2394
2395         }
2396
2397         pAppResource = UiApp::GetInstance()->GetAppResource();
2398
2399         if (pAppResource != null)
2400         {
2401                 pbgActive = pAppResource->GetBitmapN(IDB_EDIT_BACKGROUND, BITMAP_PIXEL_FORMAT_ARGB8888);
2402
2403                 if (pbgActive == null)
2404                 {
2405
2406                         if (pItem != null)
2407                         {
2408                                 delete pItem;
2409                                 pItem = null;
2410                         }
2411
2412                         return null;
2413                 }
2414         }
2415         pItem->SetElement(text, null);
2416         r = pItem->SetBackgroundBitmap(pbgActive);
2417
2418         if (pbgActive != null)
2419         {
2420                 delete pbgActive;
2421                 pbgActive = null;
2422         }
2423
2424         pItem->SetTextColor(ITEM_TEXT_COLOR);
2425         return pItem;
2426 }
2427
2428 ListItemBase*
2429 AlarmEditorForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
2430 {
2431         result r = E_SUCCESS;
2432
2433         String titleText = L"";
2434         String mainText = CommonUtil::GetString("IDS_ALM_BODY_TYPE");
2435         String defaultTitleText = L"default";
2436
2437         int fontSize = 0;
2438         ClockApp* pClock = static_cast<ClockApp*>(ClockApp::GetInstance());
2439         fontSize = pClock->GetFontSize();
2440         AppLog("fontsize:%d",fontSize);
2441
2442         if (itemIndex == 0)
2443         {
2444                 DropDownCustomItem* pItem = new (std::nothrow) DropDownCustomItem();
2445                 r = pItem->Construct(itemWidth, fontSize);
2446
2447                 if (IsFailed(r))
2448                 {
2449                         delete pItem;
2450                         return null;
2451                 }
2452
2453                 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, Color(241, 238, 233));
2454                 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, Color(86, 135, 193));
2455                 pItem->SetMainText(mainText);
2456
2457                 if (__typeName == 0)
2458                 {
2459                         __typeNameValue = CommonUtil::GetString(L"IDS_ALM_BODY_MELODY");
2460                 }
2461
2462                 if (__typeName == 1)
2463                 {
2464                         __typeNameValue = CommonUtil::GetString(L"IDS_ALM_BODY_ALERTTYEP_VIBRATION");
2465                 }
2466
2467                 if (__typeName == 2)
2468                 {
2469                         __typeNameValue = CommonUtil::GetString(L"IDS_ALM_BODY_ALERTTYEP_MELODY_AND_VIBRATION");
2470                 }
2471
2472                 pItem->SetSubText(__typeNameValue);
2473
2474                 if (!__showType)
2475                 {
2476                         pItem->SetCurState(DROP_DOWN_ITEM_STATE_CLOSED);
2477                 }
2478                 else
2479                 {
2480                         pItem->SetCurState(DROP_DOWN_ITEM_STATE_OPENED);
2481                 }
2482
2483                 r = pItem->MakeElements(fontSize);
2484
2485                 if (IsFailed(r))
2486                 {
2487                         delete pItem;
2488                         return null;
2489                 }
2490
2491                 return pItem;
2492         }
2493
2494         if (__showType && (itemIndex > 0 && itemIndex < 4))
2495         {
2496                 AppLog("the selected index is %d", __selectedIndex);
2497                 switch (itemIndex)
2498                 {
2499                 case 1:
2500                 {
2501                         titleText = CommonUtil::GetString(L"IDS_ALM_BODY_MELODY");
2502                 }
2503                 break;
2504
2505                 case 2:
2506                 {
2507                         titleText = CommonUtil::GetString(L"IDS_ALM_BODY_ALERTTYEP_VIBRATION");
2508                 }
2509                 break;
2510
2511                 case 3:
2512                 {
2513                         titleText = CommonUtil::GetString(L"IDS_ALM_BODY_ALERTTYEP_MELODY_AND_VIBRATION");
2514                 }
2515                 break;
2516                 }
2517
2518                 RadioCustomItem* pItem = new (std::nothrow) RadioCustomItem();
2519
2520                 r = pItem->Construct(itemWidth, fontSize);
2521
2522                 if (IsFailed(r))
2523                 {
2524                         delete pItem;
2525                         return null;
2526                 }
2527
2528                 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, Color(241, 238, 233));
2529                 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, Color(86, 135, 193));
2530                 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_HIGHLIGHTED, Color(86, 135, 193));
2531
2532                 pItem->SetText(titleText);
2533
2534                 if (__selectedIndex == itemIndex)
2535                 {
2536                         pItem->SetSelected(true);
2537                 }
2538                 else
2539                 {
2540                         pItem->SetSelected(false);
2541                 }
2542
2543                 if (pItem->GetSelected())
2544                 {
2545                         __typeNameValue = pItem->GetText();
2546                 }
2547
2548                 pItem->Make(fontSize);
2549                 return pItem;
2550         }
2551
2552         if ((itemIndex == 1 && !__showType) || (itemIndex == 4 && __showType))
2553         {
2554
2555                 DefaultCustomItem* pItem = new (std::nothrow) DefaultCustomItem();
2556                 String ringTone = __pAlarm->GetRingTone();
2557                 __audioFilePath = ringTone;
2558                 if(File::IsFileExist(__audioFilePath) == false)
2559                 {
2560                         __audioFilePath = AlarmPresentationModel::GetInstance()->defaultAudioPath;
2561                         __pAlarm->SetRingTone(__audioFilePath);
2562                         ringTone = __audioFilePath;
2563                 }
2564                 String titleText = CommonUtil::GetString(L"IDS_ALM_BODY_TONE");
2565                 if(__typeName == 1)
2566                 {
2567                         r = pItem->Construct(itemWidth, fontSize);
2568                 }
2569                 else
2570                 {
2571                         r = pItem->Construct(itemWidth, fontSize);
2572                 }
2573
2574                 if (IsFailed(r))
2575                 {
2576                         delete pItem;
2577                         return null;
2578                 }
2579
2580                 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, Color(241, 238, 233));
2581                 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, Color(86, 135, 193));
2582                 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_HIGHLIGHTED, Color(86, 135, 193));
2583
2584                 pItem->SetText(titleText);
2585                 int index = 0;
2586                 while(ringTone.Contains(L"/"))
2587                 {
2588                         ringTone.IndexOf('/', 0, index);
2589                         ringTone.Remove(0, index + 1);
2590                 }
2591                 pItem->SetSubText(ringTone);
2592
2593                 pItem->Make(fontSize);
2594
2595                 return pItem;
2596         }
2597         return null;
2598 }
2599
2600 ListItemBase*
2601 AlarmEditorForm::CreateItem(int itemIndex, int itemWidth)
2602 {
2603         result r = E_SUCCESS;
2604         String repeatFlag;
2605         String flag;
2606         String titleText;
2607         int itemHeight = 112;
2608
2609         int fontSize = 0;
2610         ClockApp* pClock = static_cast<ClockApp*>(ClockApp::GetInstance());
2611         fontSize = pClock->GetFontSize();
2612
2613         if (itemIndex == 0)
2614         {
2615                 ToggleCustomItem* pItem = new (std::nothrow) ToggleCustomItem();
2616                 titleText = CommonUtil::GetString(L"IDS_ALM_BODY_SNOOZE");
2617                 r = pItem->Construct(itemWidth, itemHeight);
2618                 if (IsFailed(r))
2619                 {
2620                         delete pItem;
2621                         return null;
2622                 }
2623
2624                 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, Color(241, 238, 233));
2625                 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, Color(86, 135, 193));
2626                 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_HIGHLIGHTED, Color(86, 135, 193));
2627                 pItem->SetText(titleText);
2628
2629                 pItem->Make();
2630
2631                 return pItem;
2632         }
2633
2634         else
2635         {
2636                 DefaultCustomItem* pItem = new (std::nothrow) DefaultCustomItem();
2637                 titleText = CommonUtil::GetString(L"IDS_ALM_BODY_SNOOZE_DURATION");
2638                 titleText.Append(" & ");
2639                 titleText.Append(CommonUtil::GetString(L"IDS_ALM_BODY_REPEAT"));
2640                 r = pItem->Construct(itemWidth, fontSize);
2641                 if (IsFailed(r))
2642                 {
2643                         delete pItem;
2644                         return null;
2645                 }
2646
2647                 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, Color(241, 238, 233));
2648                 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, Color(86, 135, 193));
2649                 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_HIGHLIGHTED, Color(86, 135, 193));
2650
2651                 pItem->SetText(titleText);
2652                 pItem->SetSubText(__snoozeDurationValue);
2653
2654                 r = pItem->Make(fontSize);
2655
2656                 if (IsFailed(r))
2657                 {
2658                         delete pItem;
2659                         return null;
2660                 }
2661
2662                 return pItem;
2663         }
2664         return null;
2665 }
2666
2667 bool
2668 AlarmEditorForm::DeleteGroupItem(int groupIndex, GroupItem* pItem, int itemWidth)
2669 {
2670         delete pItem;
2671         pItem = null;
2672         return true;
2673 }
2674
2675 bool
2676 AlarmEditorForm::DeleteItem(int groupIndex, int itemIndex, ListItemBase* pItem, int itemWidth)
2677 {
2678         delete pItem;
2679         pItem = null;
2680         return true;
2681 }
2682
2683 bool
2684 AlarmEditorForm::DeleteItem(int itemIndex, ListItemBase* pItem, int itemWidth)
2685 {
2686         delete pItem;
2687         pItem = null;
2688         return true;
2689 }
2690
2691 int
2692 AlarmEditorForm::GetGroupCount(void)
2693 {
2694         return 1;
2695 }
2696
2697 int
2698 AlarmEditorForm::GetItemCount(void)
2699 {
2700         if (__pAlarm != null && __pAlarm->GetSnoozeOn() == false)
2701         {
2702                 __snoozeStatus = false;
2703                 return 1;
2704         }
2705         else
2706         {
2707                 __snoozeStatus = true;
2708                 return 2;
2709         }
2710 }
2711
2712 int
2713 AlarmEditorForm::GetItemCount(int groupIndex)
2714 {
2715         if (__showType == true)
2716         {
2717                 if (__typeName == 1)
2718                 {
2719                         return 4;
2720                 }
2721                 return 5;
2722         }
2723         else
2724         {
2725                 if (__typeName == 1)
2726                 {
2727                         return 1;
2728                 }
2729                 return 2;
2730         }
2731 }
2732
2733 void
2734 AlarmEditorForm::OnGroupedListViewItemStateChanged(GroupedListView& listView, int groupIndex, int itemIndex, int elementId, ListItemStatus status)
2735 {
2736         result r = E_SUCCESS;
2737         AppControl* pAc = null;
2738
2739         Frame* pFrame = dynamic_cast<Frame*>(GetParent());
2740         if(pFrame)
2741         {
2742                 Form *pForm = pFrame->GetCurrentForm();
2743                 if(pForm->GetHashCode() != this->GetHashCode())
2744                 {
2745                         return;
2746                 }
2747         }
2748
2749         if (itemIndex == 0)
2750         {
2751                 if(__showType == true)
2752                 {
2753                         __showType = !__showType;
2754                         r = __pGroupedListView->RefreshList(0, 1, LIST_REFRESH_TYPE_ITEM_REMOVE);
2755                         r = __pGroupedListView->RefreshList(0, 1, LIST_REFRESH_TYPE_ITEM_REMOVE);
2756                         r = __pGroupedListView->RefreshList(0, 1, LIST_REFRESH_TYPE_ITEM_REMOVE);
2757                 }
2758                 else if(__showType == false)
2759                 {
2760                         __showType = !__showType;
2761                         r = __pGroupedListView->RefreshList(0, 1, LIST_REFRESH_TYPE_ITEM_ADD);
2762                         r = __pGroupedListView->RefreshList(0, 2, LIST_REFRESH_TYPE_ITEM_ADD);
2763                         r = __pGroupedListView->RefreshList(0, 3, LIST_REFRESH_TYPE_ITEM_ADD);
2764                 }
2765
2766                 r = __pGroupedListView->RefreshList(0, 0, LIST_REFRESH_TYPE_ITEM_MODIFY);
2767                 r = __pGroupedListView->RefreshList(0, 1, LIST_REFRESH_TYPE_ITEM_MODIFY);
2768                 r = __pGroupedListView->RefreshList(0, 2, LIST_REFRESH_TYPE_ITEM_MODIFY);
2769                 r = __pGroupedListView->RefreshList(0, 3, LIST_REFRESH_TYPE_ITEM_MODIFY);
2770                 r = __pGroupedListView->RefreshList(0, 4, LIST_REFRESH_TYPE_ITEM_MODIFY);
2771
2772                 RearrangeControls();
2773         }
2774         else
2775         {
2776                 if(__showType && itemIndex == 1)
2777                 {
2778                         __selectedIndex = itemIndex;
2779
2780                         if (__typeName != 0 && __typeName != 2)
2781                         {
2782                                 r = __pGroupedListView->RefreshList(0, 4, LIST_REFRESH_TYPE_ITEM_ADD);
2783                         }
2784
2785                         __typeName = __selectedIndex - 1;
2786                         r = __pGroupedListView->RefreshList(0, 0, LIST_REFRESH_TYPE_ITEM_MODIFY);
2787                         r = __pGroupedListView->RefreshList(0, 1, LIST_REFRESH_TYPE_ITEM_MODIFY);
2788                         r = __pGroupedListView->RefreshList(0, 2, LIST_REFRESH_TYPE_ITEM_MODIFY);
2789                         r = __pGroupedListView->RefreshList(0, 3, LIST_REFRESH_TYPE_ITEM_MODIFY);
2790                         r = __pGroupedListView->RefreshList(0, 4, LIST_REFRESH_TYPE_ITEM_MODIFY);
2791                 }
2792                 if(__showType && itemIndex == 2)
2793                 {
2794                         __selectedIndex = itemIndex;
2795                         __typeName = __selectedIndex - 1;
2796                         r = __pGroupedListView->RefreshList(0, 0, LIST_REFRESH_TYPE_ITEM_MODIFY);
2797                         r = __pGroupedListView->RefreshList(0, 1, LIST_REFRESH_TYPE_ITEM_MODIFY);
2798                         r = __pGroupedListView->RefreshList(0, 2, LIST_REFRESH_TYPE_ITEM_MODIFY);
2799                         r = __pGroupedListView->RefreshList(0, 3, LIST_REFRESH_TYPE_ITEM_MODIFY);
2800                         r = __pGroupedListView->RefreshList(0, 4, LIST_REFRESH_TYPE_ITEM_REMOVE);
2801                 }
2802                 if(__showType && itemIndex == 3)
2803                 {
2804                         __selectedIndex = itemIndex;
2805
2806                         if (__typeName != 0 && __typeName != 2)
2807                         {
2808                                 r = __pGroupedListView->RefreshList(0, 4, LIST_REFRESH_TYPE_ITEM_ADD);
2809                         }
2810
2811                         __typeName = __selectedIndex - 1;
2812                         r = __pGroupedListView->RefreshList(0, 0, LIST_REFRESH_TYPE_ITEM_MODIFY);
2813                         r = __pGroupedListView->RefreshList(0, 1, LIST_REFRESH_TYPE_ITEM_MODIFY);
2814                         r = __pGroupedListView->RefreshList(0, 2, LIST_REFRESH_TYPE_ITEM_MODIFY);
2815                         r = __pGroupedListView->RefreshList(0, 3, LIST_REFRESH_TYPE_ITEM_MODIFY);
2816                         r = __pGroupedListView->RefreshList(0, 4, LIST_REFRESH_TYPE_ITEM_MODIFY);
2817
2818                 }
2819
2820                 if ((itemIndex == 1 && !__showType )||(itemIndex == 4 && __showType))
2821                 {
2822                         __pBtnHourDisplay->RemoveActionEventListener(*this);
2823                         __pBtnMinDisplay->RemoveActionEventListener(*this);
2824                         __pEditField->SetEnabled(false);
2825
2826
2827                         if(__isAppControlCompleted == true)
2828                         {
2829                                 return;
2830                         }
2831
2832
2833                         pAc = AppManager::FindAppControlN(L"tizen.filemanager", L"http://tizen.org/appcontrol/operation/pick");
2834
2835                         if (pAc != null)
2836                         {
2837                                 HashMap *pHashMap = new HashMap();
2838
2839                                 if(pHashMap != null)
2840                                 {
2841                                         pHashMap->Construct();
2842                                         pHashMap->Add(*new String("http://tizen.org/appcontrol/data/selection/mode"), * new String("single"));
2843                                         String* mimeType = new String("audio/*");
2844                                         SetFormBackEventListener(null);
2845                                         __isAppControlCompleted = true;
2846                                         r = pAc->Start(null, mimeType, pHashMap, this);
2847                                         AppLogDebug("the result is %s", GetErrorMessage(r));
2848
2849                                         delete pAc;
2850                                         pAc = null;
2851
2852                                         if (mimeType != null)
2853                                         {
2854                                                 delete mimeType;
2855                                                 mimeType = null;
2856                                         }
2857
2858                                         pHashMap->RemoveAll();
2859                                         delete pHashMap;
2860                                         pHashMap = null;
2861
2862                                 }
2863
2864                         }
2865
2866                         r = __pGroupedListView->RefreshList(0, 0, LIST_REFRESH_TYPE_ITEM_MODIFY);
2867                         r = __pGroupedListView->RefreshList(0, itemIndex, LIST_REFRESH_TYPE_ITEM_MODIFY);
2868
2869                 }
2870                 RearrangeControls();
2871         }
2872
2873 }
2874
2875 void
2876 AlarmEditorForm::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
2877 {
2878         AppLog("AlarmEditorForm::OnOrientationChanged");
2879
2880         if (__pGroupedListView != null)
2881         {
2882                 __pGroupedListView->UpdateList();
2883         }
2884
2885         if (__pScrollPanel != null)
2886         {
2887                 AppLog("the height of client is %d", GetClientAreaBounds().height);
2888                 __pScrollPanel->SetBounds(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height);
2889                 //__pScrollPanel->SetScrollBarVisible(true);
2890         }
2891
2892         RearrangeControls();
2893
2894         if (__pEditField->HasFocus() == true && __pScrollPanel != null)
2895         {
2896                 AppLog("coming here");
2897                 //__pScrollPanel->SetScrollPosition(10000,false);
2898                 //__pScrollPanel->Invalidate(false);
2899                 __pScrollPanel->ScrollToBottom();
2900
2901         }
2902
2903         if (orientationStatus == ORIENTATION_STATUS_LANDSCAPE && (__pBtnHourDisplay->HasFocus() == true || __pBtnMinDisplay->HasFocus() == true) && __pScrollPanel != null)
2904         {
2905                 __pScrollPanel->SetScrollPosition(0);
2906         }
2907
2908         if (!__pEditField->HasFocus())
2909         {
2910                 if (__pHourImf->GetInputPanelBounds().height > 0 )
2911                 {
2912                         __inputConnectionHeight = __pHourImf->GetInputPanelBounds().height;
2913                         SetBounds(Rectangle(0, 0, GetBounds().width, GetBounds().height - __inputConnectionHeight));
2914                 }
2915                 else if (__pMinImf->GetInputPanelBounds().height > 0)
2916                 {
2917                         __inputConnectionHeight = __pMinImf->GetInputPanelBounds().height;
2918                         SetBounds(Rectangle(0, 0, GetBounds().width, GetBounds().height - __inputConnectionHeight));
2919                 }
2920         }
2921
2922         Invalidate(true);
2923 }
2924
2925 void
2926 AlarmEditorForm::RearrangeControls(void)
2927 {
2928
2929         int panelHeight = __pSlider->GetHeight();
2930         int list1HeightOff = 256 ;
2931         int list1HeightOn = 592 ;
2932         int list2HeightOff = 256 ;
2933         int list2HeightOn = 256 ;
2934
2935         int editFieldHeight = 0;
2936         int heightOffset = 0;
2937
2938         ClockApp* pClock = static_cast<ClockApp*>(ClockApp::GetInstance());
2939         heightOffset = pClock->GetHeightOffset();
2940         AppLog("the offset: %d",heightOffset);
2941
2942         //if (pClock->GetFontSize() != 44)
2943         {
2944                 editFieldHeight = pClock->GetFontSize()+40;
2945         }
2946         if (__pGroupedListView == NULL || __pListView == NULL || __pEditField == NULL)
2947         {
2948                 return;
2949         }
2950
2951         if(__typeName == 1)
2952         {
2953                 list1HeightOn -= (128 + heightOffset);
2954                 list1HeightOff -= (128 + heightOffset);
2955         }
2956
2957         list1HeightOn += 5 * heightOffset;
2958         list1HeightOff += 2 * heightOffset;
2959         list2HeightOn += heightOffset;
2960         list2HeightOff += heightOffset;
2961
2962         if (__showType == false)
2963         {
2964
2965                 __pGroupedListView->SetBounds(Rectangle(__pGroupedListView->GetBounds().x,__pGroupedListView->GetBounds().y, __pGroupedListView->GetWidth(), list1HeightOff));
2966                 if(__typeName != 1)
2967                 {
2968                         __pSlider->SetShowState(true);
2969                         __pSlider->SetBounds(Rectangle(__pSlider->GetX(),__pGroupedListView->GetY()+__pGroupedListView->GetHeight(), __pSlider->GetWidth(), __pSlider->GetHeight()));
2970                         __pListView->SetBounds(Rectangle(__pListView->GetBounds().x,__pSlider->GetY()+__pSlider->GetHeight(), __pListView->GetWidth(), list2HeightOff));
2971                 }
2972                 else
2973                 {
2974                         __pSlider->SetShowState(false);
2975                         __pListView->SetBounds(Rectangle(__pListView->GetBounds().x,__pGroupedListView->GetY()+__pGroupedListView->GetHeight(), __pListView->GetWidth(), list2HeightOff));
2976                 }
2977
2978                 __pLabelEditfieldTitle->SetBounds(Rectangle(__pLabelEditfieldTitle->GetX(),__pListView->GetY()+__pListView->GetHeight()+15, __pLabelEditfieldTitle->GetWidth(), __pLabelEditfieldTitle->GetHeight()));
2979                 __pEditField->SetBounds(Rectangle(__pEditField->GetX(), __pLabelEditfieldTitle->GetY()+__pLabelEditfieldTitle->GetHeight(), __pEditField->GetWidth(),editFieldHeight /*__pEditField->GetHeight()+editFieldOffset*/));
2980                 if(__typeName == 1)
2981                 {
2982                         panelHeight = __pEditField->GetHeight()+ __pListView->GetHeight() + __pGroupedListView->GetHeight() + __pLabelEditfieldTitle->GetHeight()+35;
2983                 }
2984                 else
2985                 {
2986                         panelHeight = __pEditField->GetHeight()+ __pListView->GetHeight() + __pGroupedListView->GetHeight() + __pSlider->GetHeight()+__pLabelEditfieldTitle->GetHeight()+35;
2987                 }
2988                 __pPanelList->SetBounds(Rectangle(__pPanelList->GetX(), __pPanelList->GetY(), __pPanelList->GetWidth(), panelHeight));
2989         }
2990         else
2991         {
2992                 __pGroupedListView->SetBounds(Rectangle(__pGroupedListView->GetBounds().x,__pGroupedListView->GetBounds().y, __pGroupedListView->GetWidth(), list1HeightOn));
2993                 if(__typeName != 1)
2994                 {
2995                         __pSlider->SetShowState(true);
2996                         __pSlider->SetBounds(Rectangle(__pSlider->GetX(),__pGroupedListView->GetY()+__pGroupedListView->GetHeight(), __pSlider->GetWidth(), __pSlider->GetHeight()));
2997                         __pListView->SetBounds(Rectangle(__pListView->GetBounds().x,__pSlider->GetY()+__pSlider->GetHeight(), __pListView->GetWidth(), list2HeightOn));
2998                 }
2999                 else
3000                 {
3001                         __pSlider->SetShowState(false);
3002                         __pListView->SetBounds(Rectangle(__pListView->GetBounds().x,__pGroupedListView->GetY()+__pGroupedListView->GetHeight(), __pListView->GetWidth(), list2HeightOn));
3003                 }
3004                 __pLabelEditfieldTitle->SetBounds(Rectangle(__pLabelEditfieldTitle->GetX(),__pListView->GetY()+__pListView->GetHeight()+15, __pLabelEditfieldTitle->GetWidth(),__pLabelEditfieldTitle->GetHeight()));
3005                 __pEditField->SetBounds(Rectangle(__pEditField->GetX(), __pLabelEditfieldTitle->GetY()+__pLabelEditfieldTitle->GetHeight(), __pEditField->GetWidth(), editFieldHeight/*__pEditField->GetHeight()*/));
3006                 if(__typeName == 1)
3007                 {
3008                         panelHeight = __pEditField->GetHeight()+ __pListView->GetHeight() + __pGroupedListView->GetHeight() + __pLabelEditfieldTitle->GetHeight()+35;
3009                 }
3010                 else
3011                 {
3012                         panelHeight = __pEditField->GetHeight()+ __pListView->GetHeight() + __pGroupedListView->GetHeight() + __pSlider->GetHeight()+__pLabelEditfieldTitle->GetHeight()+35;
3013                 }
3014                 __pPanelList->SetBounds(Rectangle(__pPanelList->GetX(), __pPanelList->GetY(), __pPanelList->GetWidth(), panelHeight));
3015         }
3016
3017         if (__pAlarm->GetSnoozeOn() == false)
3018         {
3019                 __pListView->SetBounds(Rectangle(__pListView->GetBounds().x,__pListView->GetBounds().y, __pListView->GetWidth(), 112));
3020                 __pLabelEditfieldTitle->SetBounds(Rectangle(__pLabelEditfieldTitle->GetX(),__pListView->GetY() + __pListView->GetHeight(), __pLabelEditfieldTitle->GetWidth(), __pLabelEditfieldTitle->GetHeight()));
3021                 __pEditField->SetBounds(Rectangle(__pEditField->GetX(), __pLabelEditfieldTitle->GetY()+__pLabelEditfieldTitle->GetHeight(), __pEditField->GetWidth(),editFieldHeight /*__pEditField->GetHeight()*/));
3022                 if(__typeName == 1)
3023                 {
3024                         panelHeight = __pEditField->GetHeight()+ __pListView->GetHeight() + __pGroupedListView->GetHeight() + __pLabelEditfieldTitle->GetHeight()+35;
3025                 }
3026                 else
3027                 {
3028                         panelHeight = __pEditField->GetHeight()+ __pListView->GetHeight() + __pGroupedListView->GetHeight() + __pSlider->GetHeight()+__pLabelEditfieldTitle->GetHeight()+35;
3029                 }
3030                 __pPanelList->SetBounds(Rectangle(__pPanelList->GetX(),__pPanelList->GetY(), __pPanelList->GetWidth(), panelHeight));
3031         }
3032         else
3033         {
3034                 __pListView->SetBounds(Rectangle(__pListView->GetBounds().x,__pListView->GetBounds().y, __pListView->GetWidth(), 240 + heightOffset));
3035                 __pLabelEditfieldTitle->SetBounds(Rectangle(__pLabelEditfieldTitle->GetX(), __pListView->GetY() + __pListView->GetHeight(), __pLabelEditfieldTitle->GetWidth(), __pLabelEditfieldTitle->GetHeight()));
3036                 __pEditField->SetBounds(Rectangle(__pEditField->GetX(), __pLabelEditfieldTitle->GetY()+__pLabelEditfieldTitle->GetHeight(), __pEditField->GetWidth(),editFieldHeight /*__pEditField->GetHeight()*/));
3037                 if(__typeName == 1)
3038                 {
3039                         panelHeight = __pEditField->GetHeight()+ __pListView->GetHeight() + __pGroupedListView->GetHeight() + __pLabelEditfieldTitle->GetHeight()+35;
3040                 }
3041                 else
3042                 {
3043                         panelHeight = __pEditField->GetHeight()+ __pListView->GetHeight() + __pGroupedListView->GetHeight() + __pSlider->GetHeight()+__pLabelEditfieldTitle->GetHeight()+35;
3044                 }
3045                 __pPanelList->SetBounds(Rectangle(__pGroupedListView->GetX(),__pPanelList->GetY(), __pPanelList->GetWidth(), panelHeight));
3046         }
3047
3048         if (__pPanelList->GetShowState() == false)
3049         {
3050                 AppLog("coming here");
3051                 AppLog("the client height is %d", GetClientAreaBounds().height);
3052                 panelHeight = GetClientAreaBounds().height - __pBtnMore->GetY();
3053
3054                 if (panelHeight < 0)
3055                 {
3056                         panelHeight = 0;
3057                 }
3058                 __pPanelList->SetBounds(Rectangle(__pPanelList->GetX(), __pPanelList->GetY(), __pPanelList->GetWidth(), panelHeight));
3059
3060                 if (__pScrollPanel != null)
3061                 {
3062                         __pScrollPanel->SetScrollBarVisible(false);
3063                         AppLog("Scroll Panel: y: %d h:%d", __pScrollPanel->GetY(), __pScrollPanel->GetHeight());
3064                 }
3065         }
3066         AppLog("PanelList: y: %d h:%d", __pPanelList->GetY(), __pPanelList->GetHeight());
3067         Invalidate(true);
3068         AppLog("PanelList: y: %d h:%d", __pPanelList->GetY(), __pPanelList->GetHeight());
3069
3070 }
3071
3072 void
3073 AlarmEditorForm::OnKeypadClosed(Control& source)
3074 {
3075         AppLog("OnKeypadClosed");
3076
3077         if (Clipboard::GetInstance()->IsPopupVisible() == false)
3078         {
3079                 GetHeader()->RemoveAllButtons();
3080                 SetActionBarsVisible(FORM_ACTION_BAR_HEADER, false);
3081                 SetActionBarsVisible(FORM_ACTION_BAR_FOOTER, true);
3082                 __pScrollPanel->SetBounds(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height);
3083         }
3084         else
3085         {
3086                 Clipboard::GetInstance()->ShowPopup(CLIPBOARD_DATA_TYPE_TEXT, *this);
3087                 AppLog("the client height is %d", GetClientAreaBounds().height);
3088         }
3089
3090         RearrangeControls();
3091
3092         Invalidate(true);
3093
3094         return;
3095 }
3096
3097 void
3098 AlarmEditorForm::OnKeypadOpened(Control& source)
3099 {
3100         ButtonItem save;
3101         ButtonItem cancel;
3102         Header* pHeader = GetHeader();
3103         String textEntered = L"";
3104
3105         if (__pEditField != null)
3106         {
3107                 textEntered = __pEditField->GetText();
3108         }
3109         textEntered.Trim();
3110
3111         if (pHeader == null)
3112         {
3113                 return;
3114         }
3115
3116         if (__player)
3117         {
3118                 __player->Stop();
3119         }
3120
3121         if (&source == (static_cast<Control*>(__pEditField)))
3122         {
3123                 GetFooter()->SetShowState(true);
3124                 GetFooter()->Invalidate(true);
3125
3126                 if ( __pEditField != null)
3127                 {
3128                         String alarmName = __pEditField->GetText();
3129                         alarmName.Trim();
3130                         if(alarmName.GetLength() == 0)
3131                         {
3132                                 GetFooter()->SetItemEnabled(0,false);
3133                         }
3134                         else
3135                         {
3136                                 GetFooter()->SetItemEnabled(0,true);
3137                         }
3138
3139                         if (__pScrollPanel != null)
3140                         {
3141                                 __pScrollPanel->SetBounds(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height);
3142                                 __pScrollPanel->ScrollToBottom();
3143                         }
3144                 }
3145         }
3146
3147         if ( (__pEditField != null && textEntered.GetLength() == 0) || (__pBtnHourDisplay->GetText().GetLength() == 0 || __pBtnMinDisplay->GetText().GetLength() == 0) )
3148         {
3149                 GetFooter()->SetItemEnabled(0, false);
3150         }
3151         else
3152         {
3153                 GetFooter()->SetItemEnabled(0, true);
3154         }
3155
3156         Invalidate(true);
3157         return;
3158 }
3159
3160 void
3161 AlarmEditorForm::OnKeypadWillOpen(Control& source)
3162 {
3163
3164 }
3165
3166 void
3167 AlarmEditorForm::OnKeypadBoundsChanged(Tizen::Ui::Control& source)
3168 {
3169         AppLog("AlarmEditorForm::OnKeypadBoundsChanged");
3170 }
3171
3172
3173 void
3174 AlarmEditorForm::OnTextValueChanged(const Control& source)
3175 {
3176         AppLog("AlarmEditorForm::OnTextValueChanged");
3177         String textEntered = L"";
3178         Header* pHeader = GetHeader();
3179         String hourValue;
3180         String minValue;
3181         result r = E_FAILURE;
3182         MessageBox __pMsgBox;
3183
3184         if (__pEditField == null)
3185         {
3186                 return;
3187         }
3188
3189         if (__pEditField != null)
3190         {
3191                 textEntered = __pEditField->GetText();
3192         }
3193         textEntered.Trim();
3194
3195         if ( __pEditField && textEntered.GetLength() == 0 )
3196         {
3197                 GetFooter()->SetItemEnabled(0, false);
3198         }
3199         else
3200         {
3201                 GetFooter()->SetItemEnabled(0, true);
3202         }
3203
3204         pHeader->SetTitleText(textEntered);
3205
3206         __pLabelTitle->SetText(textEntered);
3207
3208         if ( (__pEditField != null && textEntered.GetLength() == 0) || (__pBtnHourDisplay->GetText().GetLength() == 0 || __pBtnMinDisplay->GetText().GetLength() == 0) )
3209         {
3210                 GetFooter()->SetItemEnabled(0, false);
3211         }
3212         else
3213         {
3214                 GetFooter()->SetItemEnabled(0, true);
3215         }
3216
3217         Invalidate(true);
3218
3219         if ( __pEditField->GetTextLength() >= 250 && &source == __pEditField && __showMessageBox)
3220         {
3221
3222                 __pEditField->RemoveTextEventListener(*this);
3223                 String msg = CommonUtil::GetString("IDS_MAX_CHARACTER_LIMIT_MESSAGE");
3224                 r = __pMsgBox.Construct(L"", msg, MSGBOX_STYLE_NONE, 3000);
3225                 AppLog("the result is %s", GetErrorMessage(r));
3226                 __pMsgBox.ShowAndWait(__modalMsgBoxResult);
3227                 __pEditField->AddTextEventListener(*this);
3228                 __pEditField->ShowKeypad();
3229         }
3230         __showMessageBox = true;
3231         return;
3232 }
3233
3234 void
3235 AlarmEditorForm::OnTextValueChangeCanceled(const Control& source)
3236 {
3237
3238         GetHeader()->SetTitleText(__defaultEditFieldValue);
3239
3240
3241         if (__pEditField != null)
3242         {
3243                 __pEditField->SetText(__defaultEditFieldValue);
3244
3245                 if (__pEditField->GetText() == 0 )
3246                 {
3247                         GetFooter()->SetItemEnabled(0, false);
3248                 }
3249                 else
3250                 {
3251                         GetFooter()->SetItemEnabled(0, true);
3252                 }
3253         }
3254
3255         Invalidate(true);
3256         return;
3257 }
3258
3259 void
3260 AlarmEditorForm::OnTouchReleased(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo & touchInfo)
3261 {
3262         if (__pEditField)
3263         {
3264                 __pEditField->HideKeypad();
3265         }
3266 }
3267
3268 void
3269 AlarmEditorForm::OnTouchPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo & touchInfo)
3270 {
3271
3272         if(__pSlider != null && &source != __pSlider)
3273         {
3274                 __isPlaying = false;
3275                 if (__player)
3276                 {
3277                         __player->Stop();
3278                 }
3279         }
3280
3281         if (&source == __pBtnHourDisplay)
3282         {
3283                 __pBtnHourDisplay->SetFocus();
3284         }
3285         else if (&source == __pBtnMinDisplay)
3286         {
3287                 __pBtnMinDisplay->SetFocus();
3288         }
3289         else
3290         {
3291                 if (__pBtnHourDisplay->HasFocus())
3292                 {
3293                         HideHourKeypad();
3294                 }
3295                 else if (__pBtnMinDisplay->HasFocus())
3296                 {
3297                         HideMinKeypad();
3298                 }
3299                 SetFocus();
3300         }
3301         //Invalidate(true);
3302 }
3303
3304 void
3305 AlarmEditorForm::OnAppControlCompleteResponseReceived(const Tizen::App::AppId& appId, const Tizen::Base::String& operationId, Tizen::App::AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pExtraData)
3306 {
3307         ArrayList* pMediaResult = null;
3308         SetFormBackEventListener(this);
3309         __pBtnHourDisplay->AddActionEventListener(*this);
3310         __pBtnMinDisplay->AddActionEventListener(*this);
3311         __pEditField->SetEnabled(true);
3312         __pEditField->Invalidate(false);
3313
3314         AppLog("providerId: %ls, operationId: %ls, media res:%d ", appId.GetPointer(), operationId.GetPointer(), appControlResult);
3315         ///if (providerId.CompareTo(L"tizen.filemanager") == 0 && operationId.CompareTo(L"http://tizen.org/appcontrol/operation/pick") == 0)
3316         {
3317                 if (pExtraData != null)
3318                 {
3319                         pMediaResult = (ArrayList*)pExtraData->GetValue(* new String("http://tizen.org/appcontrol/data/selected"));
3320                         if(pMediaResult != null)
3321                         {
3322                                 String *pPath =  dynamic_cast<String*>(pMediaResult->GetAt(0));
3323                                 if (pPath == null)
3324                                 {
3325                                         return;
3326                                 }
3327
3328                                 __pAlarm->SetRingTone(*pPath);
3329                                 __audioFilePath = __pAlarm->GetRingTone();
3330                                 __pGroupedListView->RefreshList(0, 1, LIST_REFRESH_TYPE_ITEM_MODIFY);
3331                                 __pGroupedListView->RefreshList(0, 4, LIST_REFRESH_TYPE_ITEM_MODIFY);
3332                                 AppLog("File set : %ls", pPath->GetPointer());
3333
3334                         }
3335                         else
3336                         {
3337                                 AppLog("Media not found");
3338                         }
3339                 }
3340                 else
3341                 {
3342                         AppLog("pResultList is null");
3343                 }
3344
3345                 __isAppControlCompleted = false;
3346                 __pGroupedListView->Invalidate(true);
3347
3348                 StartAudio();
3349         }
3350 }
3351
3352 void
3353 AlarmEditorForm::OnSliderBarMoved(Tizen::Ui::Controls::Slider& source, int value)
3354 {
3355         AppLog("AlarmEditorForm::OnSliderBarMoved value = %d", value);
3356         if (__sliderValue == value)
3357         {
3358                 return;
3359         }
3360         __sliderValues.Push(value);
3361
3362         SettingInfo::RemoveSettingEventListener(*this);
3363         SettingInfo::SetValue(L"http://tizen.org/setting/sound.media.volume", value);
3364         SettingInfo::AddSettingEventListener(*this);
3365
3366         if(__pSlider)
3367         {
3368                 __pSlider->SetFocus();
3369                 __pSlider->Invalidate(false);
3370         }
3371
3372         if(__sliderValues.GetCount() == 1)
3373         {
3374                 SendUserEvent(10000, null);
3375         }
3376
3377         __sliderValue = value;
3378 }
3379
3380 void
3381 AlarmEditorForm::OnClipboardPopupClosed(const Tizen::Ui::ClipboardItem* pClipboardItem)
3382 {
3383         AppLog("OnClipboardPopupClosed");
3384
3385         if ( __pEditField != null && __pEditField->GetText() == 0 )
3386         {
3387                 GetFooter()->SetItemEnabled(0, false);
3388         }
3389         else
3390         {
3391                 GetFooter()->SetItemEnabled(0, true);
3392         }
3393
3394         GetFooter()->Invalidate(true);
3395 }
3396
3397 void
3398 AlarmEditorForm::OnSettingChanged(Tizen::Base::String& key)
3399 {
3400         if ( key == L"http://tizen.org/setting/locale.time.format.24hour")
3401         {
3402                 int hour = 0;
3403                 int minute = 0;
3404                 String hourVal, minVal;
3405                 int timeFormat = 12;
3406
3407                 minVal = __pBtnMinDisplay->GetText();
3408                 Integer::Parse(minVal, minute);
3409                 hourVal = __pBtnHourDisplay->GetText();
3410                 Integer::Parse(hourVal, hour);
3411
3412
3413                 int alarmTimeHour, alarmTimeMin;
3414                 Bitmap* pToggleBtnPMBG = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_TOGGLE_PM_BG);
3415                 Bitmap* pToggleBtnAMBG = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_TOGGLE_AM_BG);
3416
3417
3418                 SettingInfo::GetValue(key, is24HourFormat);
3419
3420                 if (is24HourFormat == true)
3421                 {
3422                         if (__defaultToggleValue == CommonUtil::GetString(L"IDS_COM_BODY_AM"))
3423                         {
3424                                 if(hour == 12)
3425                                 {
3426                                         hour = 0;
3427                                 }
3428
3429                         }
3430                         else if (__defaultToggleValue == CommonUtil::GetString(L"IDS_COM_POP_PM"))
3431                         {
3432
3433                                 if(hour != 12)
3434                                 {
3435                                         hour = hour + 12;
3436                                 }
3437
3438                         }
3439                 }
3440
3441                 alarmTimeHour = hour;
3442                 alarmTimeMin = minute;
3443
3444                 if(is24HourFormat == false)
3445                 {
3446                         if (alarmTimeHour < timeFormat)
3447                         {
3448                                 __defaultToggleValue = CommonUtil::GetString(L"IDS_COM_BODY_AM");
3449                                 __pBtnToggle->SetNormalBackgroundBitmap(*pToggleBtnAMBG);
3450                                 __pBtnToggle->SetPressedBackgroundBitmap(*pToggleBtnAMBG);
3451                         }
3452                         else
3453                         {
3454                                 alarmTimeHour = alarmTimeHour - timeFormat;
3455                                 __defaultToggleValue = CommonUtil::GetString(L"IDS_COM_POP_PM");
3456                                 __pBtnToggle->SetNormalBackgroundBitmap(*pToggleBtnPMBG);
3457                                 __pBtnToggle->SetPressedBackgroundBitmap(*pToggleBtnPMBG);
3458                         }
3459
3460                         __pBtnToggle->SetShowState(true);
3461                         __pLabelAm->SetShowState(true);
3462                         __pLabelPm->SetShowState(true);
3463                 }
3464                 else
3465                 {
3466                         __pBtnToggle->SetShowState(false);
3467                         __pLabelAm->SetShowState(false);
3468                         __pLabelPm->SetShowState(false);
3469                 }
3470
3471                 if(alarmTimeHour == 0 && is24HourFormat == false)
3472                 {
3473                         alarmTimeHour = 12;
3474                 }
3475
3476                 hourVal.Clear();
3477                 minVal.Clear();
3478
3479
3480                 if ( alarmTimeHour < 10)
3481                 {
3482                         hourVal.Append(0);
3483                 }
3484
3485                 if (alarmTimeMin < 10)
3486                 {
3487                         minVal.Append(0);
3488                 }
3489
3490                 hourVal.Append(alarmTimeHour);
3491                 minVal.Append(alarmTimeMin);
3492
3493                 __pBtnHourDisplay->SetText(hourVal);
3494                 __pBtnMinDisplay->SetText(minVal);
3495                 __pBtnHourDisplay->Invalidate(false);
3496                 __pBtnMinDisplay->Invalidate(false);
3497
3498         }
3499
3500         if (key == L"http://tizen.org/setting/sound.media.volume" )
3501         {
3502                 SettingInfo::GetValue(key, systemVolume);
3503                 if(__pSlider != NULL)
3504                 {
3505                         __pSlider->RemoveSliderEventListener(*this);
3506                         __pSlider->SetValue(systemVolume);
3507                         __pSlider->AddSliderEventListener(*this);
3508                         __pSlider->Invalidate(true);
3509                 }
3510
3511                 if (__player != null && __player->GetState() != PLAYER_STATE_PLAYING)
3512                 {
3513                         __player->SetAudioStreamType(AUDIO_STREAM_TYPE_MEDIA);
3514                         __isPlaying = true;
3515                         __player->Play();
3516                 }
3517
3518                 if(__player != null)
3519                 {
3520                         __player->SetVolume((100 * systemVolume)/15);
3521                 }
3522         }
3523 }
3524
3525 void
3526 AlarmEditorForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
3527 {
3528         if (requestId == REQUEST_ID_TERMINATE)
3529         {
3530                 SceneManager* pSceneManager = SceneManager::GetInstance();
3531
3532                 if (pSceneManager != null)
3533                 {
3534                         pSceneManager->GoBackward(BackwardSceneTransition(IDSCN_ALARM_LIST));
3535                 }
3536
3537         }
3538         else
3539         {
3540                 if (__sliderValues.GetCount())
3541                 {
3542                         int sliderValue = -1;
3543                         __sliderValues.Pop(sliderValue);
3544                         __sliderValues.RemoveAll();
3545
3546                         if(__player != null && __player->GetState() != PLAYER_STATE_PLAYING)
3547                         {
3548                                 __player->SetAudioStreamType(AUDIO_STREAM_TYPE_MEDIA);
3549                                 __isPlaying = true;
3550                                 __player->Play();
3551                         }
3552
3553                         if(__player != null)
3554                         {
3555                                 __player->SetVolume((100 * sliderValue)/15);
3556                         }
3557                 }
3558         }
3559 }
3560
3561 void
3562 AlarmEditorForm::StartAudio(void)
3563 {
3564         result r = E_SUCCESS;
3565         if (__audioFilePath != L"")
3566         {
3567                 __player->Close();
3568                 r = __player->OpenFile(__audioFilePath, false);
3569
3570                 if (IsFailed(r))
3571                 {
3572                         AppLog("the result of openfile is %s", GetErrorMessage(r));
3573                         return;
3574                 }
3575
3576                 r = __player->SetLooping(true);
3577                 __player->SetAudioStreamType(AUDIO_STREAM_TYPE_MEDIA);
3578                 r = __player->Play();
3579                 __player->SetVolume(100);
3580
3581                 if (IsFailed(r))
3582                 {
3583                         AppLog("the result of play is %s", GetErrorMessage(r));
3584                         return;
3585                 }
3586                 __player->Pause();
3587                 __isPlaying = false;
3588         }
3589 }
3590
3591 void
3592 AlarmEditorForm::OnDeviceStateChanged(Tizen::System::DeviceType deviceType, const Tizen::Base::String& state)
3593 {
3594         if(deviceType == DEVICE_TYPE_STORAGE_CARD)
3595         {
3596                 if(File::IsFileExist(__audioFilePath) == false)
3597                 {
3598                         __audioFilePath = AlarmPresentationModel::GetInstance()->defaultAudioPath;
3599                         if(__pListView != null)
3600                         {
3601                                 __pListView->UpdateList();
3602                         }
3603                 }
3604         }
3605 }
3606
3607 bool
3608 AlarmEditorForm::ValidatePastedText(const Tizen::Base::String &pastedText, Tizen::Base::String &replacedText)
3609 {
3610         AppLog("AlarmEditorForm::ValidatePastedText");
3611         MessageBox msgBox;
3612         int textLength = __pEditField->GetText().GetLength() - replacedText.GetLength() + pastedText.GetLength();
3613         if (textLength >= 250)
3614         {
3615                 __showMessageBox = false;
3616                 __pEditField->RemoveTextEventListener(*this);
3617                 String msg = CommonUtil::GetString("IDS_MAX_CHARACTER_LIMIT_MESSAGE");
3618                 msgBox.Construct(L"", msg, MSGBOX_STYLE_NONE, 3000);
3619                 msgBox.ShowAndWait(__modalMsgBoxResult);
3620                 __pEditField->AddTextEventListener(*this);
3621                 __pEditField->ShowKeypad();
3622         }
3623         return false;
3624 }
3625
3626 void
3627 AlarmEditorForm::OnFocusGained (const Tizen::Ui::Control &source)
3628 {
3629         AppLog("AlarmEditorForm::OnFocusGained");
3630         if (&source == (static_cast<Control*>(__pEditField)))
3631         {
3632                 Header* pHeader = GetHeader();
3633
3634                 if (__pEditField != null)
3635                 {
3636                         pHeader->SetTitleText(__pEditField->GetText());
3637                 }
3638
3639                 if (__pScrollPanel != null)
3640                 {
3641                         __pScrollPanel->SetBounds(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height);
3642                         //__pScrollPanel->ScrollToBottom();
3643                 }
3644                 GetFooter()->SetFocusable(true);
3645         }
3646
3647         if ((__pBtnHourDisplay != null && &source != __pBtnHourDisplay) && (__pBtnMinDisplay != null && &source != __pBtnMinDisplay))
3648         {
3649                 if (__pBtnHourDisplay->HasFocus())
3650                 {
3651                         HideHourKeypad();
3652                         SetFocus();
3653                 }
3654                 else if (__pBtnMinDisplay->HasFocus())
3655                 {
3656                         HideMinKeypad();
3657                         SetFocus();
3658                 }
3659         }
3660
3661         return;
3662 }
3663
3664
3665 void
3666 AlarmEditorForm::OnFocusLost (const Tizen::Ui::Control &source)
3667 {
3668         AppLog("AlarmEditorForm::OnFocusLost ");
3669         if(__pSlider != null && &source == __pSlider)
3670         {
3671                 __isPlaying = false;
3672                 if (__player)
3673                 {
3674                         AppLog("AlarmEditorForm::OnFocusLost 1");
3675                         result r = __player->Stop();
3676                         AppLog("AlarmEditorForm::OnFocusLost result = %s", GetErrorMessage(r));
3677                 }
3678         }
3679
3680 }
3681
3682 void
3683 AlarmEditorForm::OnInputConnectionTextCommitted(InputConnection& source, const Tizen::Base::String& committedText)
3684 {
3685         AppLog("AlarmEditorForm::OnInputConnectionTextCommitted commited text =%shi", committedText.GetPointer());
3686
3687         String val = L"00";
3688         String hourValue;
3689         String minValue;
3690         int hour = 0;
3691         int min = 0;
3692         String fullString;
3693
3694         if (__pHourImf != null && &source == __pHourImf)
3695         {
3696                 if (__hourText.GetLength() == 2)
3697                 {
3698                         fullString = __hourText;
3699                         __hourText.Clear();
3700                 }
3701                 else
3702                 {
3703                         fullString = __pBtnHourDisplay->GetText();
3704                 }
3705
3706                 fullString.Append(committedText);
3707                 __pBtnHourDisplay->SetText(fullString);
3708
3709                 hourValue = fullString;
3710                 if(hourValue.GetLength() > 2)
3711                 {
3712                         hourValue.SubString(hourValue.GetLength() - 1, val);
3713                 }
3714                 else
3715                 {
3716                         val = hourValue;
3717                 }
3718
3719                 Integer::Parse(val, hour);
3720                 if(IsFailed(GetLastResult()))
3721                 {
3722                         hour = 0;
3723                 }
3724
3725                 __pBtnHourDisplay->SetText(val);
3726
3727                 if (val.GetLength() == 2)
3728                 {
3729                         isHourClicked = false;
3730
3731                         Canvas* pCanvas = null;
3732                         Bitmap* pbgBitmap = null;
3733                         Bitmap* pFinalBitmap = null;
3734                         Bitmap* pbgFocusBitmap = null;
3735                         Bitmap* pFinalBitmapFocused = null;
3736                         Bitmap* pBgNormalBitmap = null;
3737                         Canvas* pCanvasFocused = null;
3738                         int canvasWidth = 276;
3739                         int canvasHeight = 236;
3740
3741                         pBgNormalBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_NORMAL_BG);
3742                         pbgBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_BG);
3743
3744                         pCanvas = new (std::nothrow) Canvas();
3745                         pCanvas->Construct(Rectangle(0,0,canvasWidth,canvasHeight));
3746                         pCanvas->DrawBitmap(Point(0,0),*pBgNormalBitmap);
3747                         pCanvas->DrawBitmap(Point(0,0),*pbgBitmap);
3748
3749                         if (pbgBitmap != null)
3750                         {
3751                                 delete pbgBitmap;
3752                                 pbgBitmap = null;
3753                         }
3754
3755                         if (pBgNormalBitmap != null)
3756                         {
3757                                 delete pBgNormalBitmap;
3758                                 pBgNormalBitmap = null;
3759                         }
3760
3761                         pFinalBitmap = new (std::nothrow) Bitmap();
3762
3763                         if ( pFinalBitmap != NULL)
3764                         {
3765                                 pFinalBitmap->Construct(*pCanvas,Rectangle(0,0,canvasWidth,canvasHeight));
3766                                 delete pCanvas;
3767                         }
3768
3769                         pbgFocusBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_FOCUS_BG);
3770                         pbgBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ALARM_TIME_BG);
3771
3772                         pCanvasFocused = new (std::nothrow) Canvas();
3773                         pCanvasFocused->Construct(Rectangle(0,0,canvasWidth,canvasHeight));
3774                         pCanvasFocused->DrawBitmap(Point(0,0),*pbgFocusBitmap);
3775                         pCanvasFocused->DrawBitmap(Point(0,0),*pbgBitmap);
3776
3777                         if (pbgFocusBitmap != null)
3778                         {
3779                                 delete pbgFocusBitmap;
3780                                 pbgFocusBitmap = null;
3781                         }
3782
3783                         if (pbgBitmap != null)
3784                         {
3785                                 delete pbgBitmap;
3786                                 pbgBitmap = null;
3787                         }
3788
3789                         pFinalBitmapFocused = new (std::nothrow) Bitmap();
3790
3791                         if ( pFinalBitmapFocused != null)
3792                         {
3793                                 pFinalBitmapFocused->Construct(*pCanvasFocused,Rectangle(0,0,canvasWidth,canvasHeight));
3794                                 delete pCanvasFocused;
3795                         }
3796
3797                         __pBtnMinDisplay->SetFocus();
3798                         ShowMinKeypad();
3799
3800                         __pBtnMinDisplay->SetNormalBackgroundBitmap(*pFinalBitmapFocused);
3801                         __pBtnMinDisplay->SetPressedBackgroundBitmap(*pFinalBitmapFocused);
3802                         __pBtnHourDisplay->SetNormalBackgroundBitmap(*pFinalBitmap);
3803
3804                         if (pFinalBitmap != null)
3805                         {
3806                                 delete pFinalBitmap;
3807                                 pFinalBitmap = null;
3808                         }
3809
3810                         if (pFinalBitmapFocused != null)
3811                         {
3812                                 delete pFinalBitmapFocused;
3813                                 pFinalBitmapFocused = null;
3814                         }
3815
3816                 }
3817                 if (is24HourFormat == false)
3818                 {
3819                         if (hour > 12 || fullString == "00")
3820                         {
3821                                 __pBtnHourDisplay->SetText(L"12");
3822                                 __pBtnMinDisplay->SetFocus();
3823                                 ShowMinKeypad();
3824                         }
3825
3826                         /*if (isHourClicked == false)
3827                         {
3828                                 __pBtnMinDisplay->SetFocus();
3829                                 ShowMinKeypad();
3830                         }*/
3831                 }
3832                 else
3833                 {
3834                         if (hour >= 24)
3835                         {
3836                                 __pBtnHourDisplay->SetText(L"23");
3837                                 __pBtnMinDisplay->SetFocus();
3838                                 ShowMinKeypad();
3839                         }
3840                 }
3841
3842                 __pBtnHourDisplay->Invalidate(true);
3843                 __pBtnMinDisplay->Invalidate(true);
3844         }
3845         else if (__pMinImf != null && &source == __pMinImf)
3846         {
3847                 if (__hourText.GetLength() == 2)
3848                 {
3849                         fullString = __hourText;
3850                         __hourText.Clear();
3851                 }
3852                 else
3853                 {
3854                         fullString = __pBtnMinDisplay->GetText();
3855                 }
3856
3857                 fullString.Append(committedText);
3858                 __pBtnMinDisplay->SetText(fullString);
3859
3860                 minValue = fullString;
3861                 if(minValue.GetLength() > 2)
3862                 {
3863                         minValue.SubString(minValue.GetLength() - 1, val);
3864                 }
3865                 else
3866                 {
3867                         val = minValue;
3868                 }
3869
3870
3871                 Integer::Parse(val, min);
3872
3873                 __pBtnMinDisplay->SetText(val);
3874                 //__pEditFieldHour->SetText(val);
3875                 //__hourText = val;
3876
3877                 if (val.GetLength() > 0 && min > 59)
3878                 {
3879                         __pBtnMinDisplay->SetText(L"59");
3880                         //__pEditFieldHour->SetText(L"0");
3881                         //__hourText = "0";
3882                 }
3883                 __pBtnMinDisplay->Invalidate(true);
3884         }
3885
3886         if (__pBtnHourDisplay->GetText() == "" || __pBtnMinDisplay->GetText() == "")
3887         {
3888                 GetFooter()->SetItemEnabled(0, false);
3889                 GetFooter()->Invalidate(true);
3890         }
3891         else
3892         {
3893                 GetFooter()->SetItemEnabled(0, true);
3894                 GetFooter()->Invalidate(true);
3895         }
3896
3897 }
3898
3899 result
3900 AlarmEditorForm::ShowHourKeypad()
3901 {
3902         result r = E_SUCCESS;
3903
3904         if(__pHourImf != null)
3905         {
3906                 __pHourImf->BindInputMethod();
3907                 r = __pHourImf->ShowInputPanel();
3908         }
3909
3910         return r;
3911 }
3912
3913 result
3914 AlarmEditorForm::HideHourKeypad()
3915 {
3916         result r = E_SUCCESS;
3917
3918         if (__pHourImf != null)
3919         {
3920                 r = __pHourImf->HideInputPanel();
3921                 __pHourImf->UnbindInputMethod();
3922         }
3923
3924         return r;
3925 }
3926
3927 result
3928 AlarmEditorForm::ShowMinKeypad()
3929 {
3930         result r = E_SUCCESS;
3931
3932         if(__pMinImf != null)
3933         {
3934                 __pMinImf->BindInputMethod();
3935                 r = __pMinImf->ShowInputPanel();
3936         }
3937
3938         return r;
3939 }
3940
3941 result
3942 AlarmEditorForm::HideMinKeypad()
3943 {
3944         result r = E_SUCCESS;
3945
3946         if (__pMinImf != null)
3947         {
3948                 r = __pMinImf->HideInputPanel();
3949                 __pMinImf->UnbindInputMethod();
3950         }
3951
3952         return r;
3953 }
3954
3955 void
3956 AlarmEditorForm::OnInputConnectionPanelShowStateChanged(InputConnection& source, InputPanelShowState showState)
3957 {
3958         AppLog("AlarmEditorForm::OnInputConnectionPanelShowStateChanged");
3959
3960         if ((__pHourImf != null && &source == __pHourImf) || (__pMinImf != null && &source == __pMinImf) )
3961         {
3962                 AppLog("source height = %d", source.GetInputPanelBounds().height);
3963
3964
3965                 if (showState == INPUT_PANEL_SHOW_STATE_SHOW)
3966                 {
3967                         __inputConnectionHeight = source.GetInputPanelBounds().height;
3968                         SetBounds(Rectangle(0, 0, GetBounds().width, GetBounds().height - __inputConnectionHeight));
3969                 }
3970                 else
3971                 {
3972                         SetBounds(Rectangle(0, 0, GetBounds().width, GetBounds().height + __inputConnectionHeight));
3973                         __inputConnectionHeight = 0;
3974                 }
3975
3976                 if (__pScrollPanel != null)
3977                 {
3978                         __pScrollPanel->SetBounds(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height);
3979                         __pScrollPanel->SetScrollBarVisible(true);
3980                 }
3981
3982                 GetFooter()->SetShowState(true);
3983                 GetFooter()->Invalidate(true);
3984         }
3985         Invalidate(true);
3986 }
3987
3988 void
3989 AlarmEditorForm::OnInputConnectionPanelBoundsChanged(InputConnection& source, const Rectangle& bounds)
3990 {
3991         AppLog("AlarmEditorForm::OnInputConnectionPanelBoundsChanged");
3992
3993         if (__pScrollPanel != null && (&source == __pHourImf || &source == __pMinImf))
3994         {
3995                 __pScrollPanel->ScrollToTop();
3996         }
3997 }
3998
3999 void
4000 AlarmEditorForm::OnTouchMoved(const Control& source, const Point& currentPosition, const TouchEventInfo& touchInfo)
4001 {
4002         AppLog("AlarmEditorForm::OnTouchMoved");
4003
4004         HideHourKeypad();
4005         HideMinKeypad();
4006
4007 }
4008
4009 bool
4010 AlarmEditorForm::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
4011 {
4012         AppLog("AlarmEditorForm::OnKeyPressed");
4013         String strHour = L"";
4014         String strMin = L"";
4015
4016         if(keyEventInfo.GetKeyCode() == KEY_ENTER)
4017         {
4018                 return true;
4019         }
4020
4021         if(keyEventInfo.GetKeyCode() == KEY_BACKSPACE )
4022         {
4023                 AppLog("AlarmEditorForm::OnKeyPressed:the back is clicked");
4024                 if(&source == __pBtnHourDisplay)
4025                 {
4026                         strHour = __pBtnHourDisplay->GetText();
4027                         strHour.Remove(strHour.GetLength()-1, 1);
4028                         __pBtnHourDisplay->SetText(strHour);
4029                         __pBtnHourDisplay->Invalidate(true);
4030
4031                         if(__pBtnHourDisplay->GetText() == L"")
4032                         {
4033                                 GetFooter()->SetItemEnabled(0, false);
4034                                 GetFooter()->Invalidate(true);
4035                         }
4036                 }
4037                 if(&source == __pBtnMinDisplay)
4038                 {
4039                         strMin = __pBtnMinDisplay->GetText();
4040                         strMin.Remove(strMin.GetLength()-1, 1);
4041                         __pBtnMinDisplay->SetText(strMin);
4042                         __pBtnMinDisplay->Invalidate(true);
4043
4044                         if(__pBtnMinDisplay->GetText() == L"")
4045                         {
4046                                 GetFooter()->SetItemEnabled(0, false);
4047                                 GetFooter()->Invalidate(true);
4048                         }
4049                 }
4050                 return true;
4051         }
4052         return false;
4053 }
4054
4055 bool
4056 AlarmEditorForm::OnKeyReleased(Control& source, const Tizen::Ui::KeyEventInfo& keyEventInfo)
4057 {
4058         AppLog("AlarmEditorForm::OnKeyReleased");
4059         if(keyEventInfo.GetKeyCode() == KEY_ENTER)
4060         {
4061                 __pMinImf->HideInputPanel();
4062                 __pHourImf->HideInputPanel();
4063                 return true;
4064         }
4065         if(keyEventInfo.GetKeyCode() == KEY_BACKSPACE)
4066         {
4067                 AppLog("the back is clicked");
4068                 return true;
4069         }
4070         return false;
4071 }