From: rahul varna Date: Mon, 29 Apr 2013 00:56:59 +0000 (+0900) Subject: Battery level check logic changed in camera and recorder application:N_SE-36537 X-Git-Tag: 2.2_release~77 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ade879d7520bf7f66a89ded3db3fa029e3abf324;p=samples%2Fnative%2FMediaApp.git Battery level check logic changed in camera and recorder application:N_SE-36537 Signed-off-by: rahul varna --- diff --git a/project/src/Camera/CameraCaptureForm.cpp b/project/src/Camera/CameraCaptureForm.cpp index 12d71d0..8f61899 100644 --- a/project/src/Camera/CameraCaptureForm.cpp +++ b/project/src/Camera/CameraCaptureForm.cpp @@ -1251,6 +1251,25 @@ CATCH: return; } +bool +CameraCaptureForm::IsBatteryLevelLow(void) +{ + Tizen::System::BatteryLevel batteryLevel; + Tizen::System::Battery::GetCurrentLevel(batteryLevel); + + if (batteryLevel == BATTERY_CRITICAL || batteryLevel == BATTERY_EMPTY || batteryLevel == BATTERY_LOW) + { + bool isCharging = false; + Tizen::System::RuntimeInfo::GetValue(String(L"IsCharging"), isCharging); + if (isCharging == false) + { + return true; + } + } + + return false; +} + result CameraCaptureForm::Activate(void* pActivateParam) { @@ -1263,38 +1282,28 @@ CameraCaptureForm::Activate(void* pActivateParam) Tizen::Graphics::PixelFormat pixFormat = PIXEL_FORMAT_YCbCr420_PLANAR; int tempQuality = CAMERA_QUALITY_SUPER_FINE; - Tizen::System::BatteryLevel batteryLevel; - Tizen::System::Battery::GetCurrentLevel(batteryLevel); - - if (batteryLevel == BATTERY_CRITICAL || batteryLevel == BATTERY_EMPTY || batteryLevel == BATTERY_LOW) + if (IsBatteryLevelLow() == true) { - bool isCharging = false; - Tizen::System::RuntimeInfo::GetValue(String(L"IsCharging"), isCharging); - if (isCharging == false) - { - MessageBox msgBox; - int reslut_a; - msgBox.Construct("Info", "Please Charge the Battery to use camera", MSGBOX_STYLE_OK, MESSAGE_BOX_TIMEOUT); - msgBox.ShowAndWait(reslut_a); - EnableFooterItem(ID_BUTTON_SETTING, false); - EnableFooterItem(ID_BUTTON_CAPTURE, false); - __batteryLevelFlag = true; - - //Free the resource and go back to previous form - FreeResources(); - Deactivate(); + MessageBox msgBox; + int reslut_a; + msgBox.Construct("Info", "Please Charge the Battery to use camera", MSGBOX_STYLE_OK, MESSAGE_BOX_TIMEOUT); + msgBox.ShowAndWait(reslut_a); - return E_SUCCESS; - } - else - { - ShowFooterItems(); - } + __batteryLevelFlag = true; + + ShowFooterItems(); + + //Free the resource and go back to previous form + FreeResources(); + Deactivate(); + + return E_SUCCESS; } else { ShowFooterItems(); } + __batteryLevelFlag = false; Tizen::System::PowerManager::KeepScreenOnState(true, false); __background = false; @@ -1634,6 +1643,18 @@ CameraCaptureForm::OnActionPerformed(const Tizen::Ui::Control& source, int actio case ID_BUTTON_SETTING: { + if (IsBatteryLevelLow() == true) + { + MessageBox msgBox; + int outResult; + msgBox.Construct("Info", "Please Charge the Battery to use the recorder", MSGBOX_STYLE_OK, MESSAGE_BOX_TIMEOUT); + msgBox.ShowAndWait(outResult); + + FreeResources(); + Deactivate(); + return; + } + CreateSettingPopUp(); ShowPopUp(__pPopupSetting); } @@ -1648,6 +1669,18 @@ CameraCaptureForm::OnActionPerformed(const Tizen::Ui::Control& source, int actio case ID_BUTTON_CAPTURE: { + if (IsBatteryLevelLow() == true) + { + MessageBox msgBox; + int outResult; + msgBox.Construct("Info", "Please Charge the Battery to use the recorder", MSGBOX_STYLE_OK, MESSAGE_BOX_TIMEOUT); + msgBox.ShowAndWait(outResult); + + FreeResources(); + Deactivate(); + return; + } + //disable all the buttons once capture is pressed Footer* pFotter = null; EnableFooterItem(ID_BUTTON_SETTING, false); diff --git a/project/src/Camera/CameraCaptureForm.h b/project/src/Camera/CameraCaptureForm.h index 006e18f..f788f6a 100644 --- a/project/src/Camera/CameraCaptureForm.h +++ b/project/src/Camera/CameraCaptureForm.h @@ -149,6 +149,8 @@ private: Tizen::Graphics::Bitmap* CreateBitmapFromByteBufferN(ByteBuffer* pBuffer, const int& width, const int& height); void ShowCapturedImageThumbnail(String* pFileName); Tizen::Graphics::PixelFormat GetPreviewFormat(const int& previewFormatValue); + + bool IsBatteryLevelLow(void); private: //Do not change the e-num order, if any new things are to be added add to the end of the list enum diff --git a/project/src/Recorder/AudioRecorderForm.cpp b/project/src/Recorder/AudioRecorderForm.cpp index 821f9a9..867a361 100644 --- a/project/src/Recorder/AudioRecorderForm.cpp +++ b/project/src/Recorder/AudioRecorderForm.cpp @@ -71,6 +71,7 @@ static const int INIT = -1; static int _CONTEXT_MENU_Y = 700; static const int ENABLE_AUDIO_STREAM = 0; static const int DISABLE_AUDIO_STREAM = 1; +static const int MESSAGE_BOX_TIMEOUT = 10000; static const String SECTION = L"AudioRecorder"; static const String KEY_QUALITY = L"quality"; @@ -775,6 +776,24 @@ AudioRecorderForm::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& sou return; } +bool +AudioRecorderForm::IsBatteryLevelLow(void) +{ + Tizen::System::BatteryLevel batteryLevel; + Tizen::System::Battery::GetCurrentLevel(batteryLevel); + + if (batteryLevel == BATTERY_CRITICAL || batteryLevel == BATTERY_EMPTY || batteryLevel == BATTERY_LOW) + { + bool isCharging = false; + Tizen::System::RuntimeInfo::GetValue(String(L"IsCharging"), isCharging); + if (isCharging == false) + { + return true; + } + } + + return false; +} result AudioRecorderForm::Activate(void* pActivateParam) @@ -787,21 +806,16 @@ AudioRecorderForm::Activate(void* pActivateParam) FreeResources(); - Tizen::System::BatteryLevel batteryLevel; - Tizen::System::Battery::GetCurrentLevel(batteryLevel); - - if (batteryLevel == BATTERY_CRITICAL || batteryLevel == BATTERY_EMPTY || batteryLevel == BATTERY_LOW) + if (IsBatteryLevelLow() == true) { - bool isCharging = false; - Tizen::System::RuntimeInfo::GetValue(String(L"IsCharging"), isCharging); - if (isCharging == false) - { - //Free the resource and go back to previous form - FreeResources(); - Deactivate(); - return E_SUCCESS; - } + MessageBox msgBox; + int reslut_a; + msgBox.Construct("Info", "Please Charge the Battery to use camera", MSGBOX_STYLE_OK, MESSAGE_BOX_TIMEOUT); + msgBox.ShowAndWait(reslut_a); + + Deactivate(); + return E_SUCCESS; } if (__pProgress != null) @@ -934,6 +948,18 @@ AudioRecorderForm::OnActionPerformed(const Tizen::Ui::Control& source, int actio case ID_SETTING: { + if (IsBatteryLevelLow() == true) + { + MessageBox msgBox; + int outResult; + msgBox.Construct("Info", "Please Charge the Battery to use the recorder", MSGBOX_STYLE_OK, MESSAGE_BOX_TIMEOUT); + msgBox.ShowAndWait(outResult); + + FreeResources(); + Deactivate(); + return; + } + if (RECORDER_STATE_RECORDING != __pAudioRecorder->GetState()) { __pContextMenu->SetPosition(Point(0, __contextMenuYCoordinate)); @@ -952,6 +978,20 @@ AudioRecorderForm::OnActionPerformed(const Tizen::Ui::Control& source, int actio case ID_START: { + if (IsBatteryLevelLow() == true) + { + MessageBox msgBox; + int outResult; + msgBox.Construct("Info", "Please Charge the Battery to use the recorder", MSGBOX_STYLE_OK, MESSAGE_BOX_TIMEOUT); + msgBox.ShowAndWait(outResult); + + FreeResources(); + Deactivate(); + return; + } + + TryReturnVoid(__pAudioRecorder != null, "__pAudioRecorder handle is null"); + Footer* pFotter = null; //Disable Start/Stop button until OnAudioRecorderStarted/OnAudioRecorderStopped is called ShowFooterItem(0, false); @@ -2214,15 +2254,17 @@ void AudioRecorderForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source) { AppLog("AudioRecorderForm::OnFormBackRequested called"); - TryReturnVoid(__pAudioRecorder != null, "AudioRecorder handle is null"); - //If its recording, then cancle it, else delete safely recorder handle - if (__pAudioRecorder->GetState() == RECORDER_STATE_RECORDING) + if (__pAudioRecorder != null) { - CancelAudioRecording(); - SetFooterItem(1, String(L"Start"), ID_START); - __pProgress->SetValue(0); - __backKeyPressed = true; + //If its recording, then cancle it, else delete safely recorder handle + if (__pAudioRecorder->GetState() == RECORDER_STATE_RECORDING) + { + CancelAudioRecording(); + SetFooterItem(1, String(L"Start"), ID_START); + __pProgress->SetValue(0); + __backKeyPressed = true; + } } else { diff --git a/project/src/Recorder/AudioRecorderForm.h b/project/src/Recorder/AudioRecorderForm.h index f79752e..43f3829 100644 --- a/project/src/Recorder/AudioRecorderForm.h +++ b/project/src/Recorder/AudioRecorderForm.h @@ -123,6 +123,7 @@ private: result AddListView(ListView** pListView, Popup* pPopup, int id); void DeletePopup(Popup* pPopup); bool CheckCallInProgress(void); + bool IsBatteryLevelLow(void); void ReadAudioPreProcessedFile(String fileName); void DeletePopup(Popup** pPopup); diff --git a/project/src/Recorder/VideoRecorderForm.cpp b/project/src/Recorder/VideoRecorderForm.cpp index cc367cf..e705faa 100644 --- a/project/src/Recorder/VideoRecorderForm.cpp +++ b/project/src/Recorder/VideoRecorderForm.cpp @@ -1198,6 +1198,25 @@ VideoRecorderForm::DeleteItem(int index, Tizen::Ui::Controls::ListItemBase* pIte return true; } +bool +VideoRecorderForm::IsBatteryLevelLow(void) +{ + Tizen::System::BatteryLevel batteryLevel; + Tizen::System::Battery::GetCurrentLevel(batteryLevel); + + if (batteryLevel == BATTERY_CRITICAL || batteryLevel == BATTERY_EMPTY || batteryLevel == BATTERY_LOW) + { + bool isCharging = false; + Tizen::System::RuntimeInfo::GetValue(String(L"IsCharging"), isCharging); + if (isCharging == false) + { + return true; + } + } + + return false; +} + result VideoRecorderForm::Activate(void* pActivateParam) { @@ -1216,49 +1235,33 @@ VideoRecorderForm::Activate(void* pActivateParam) AppLog("VideoRecorderForm::Activate enter CAM TYPE = %d", __camType); - Tizen::System::BatteryLevel batteryLevel; - Tizen::System::Battery::GetCurrentLevel(batteryLevel); - - if (batteryLevel == BATTERY_CRITICAL || batteryLevel == BATTERY_EMPTY || batteryLevel == BATTERY_LOW) + if (IsBatteryLevelLow() == true) { - bool isCharging = false; - Tizen::System::RuntimeInfo::GetValue(String(L"IsCharging"), isCharging); - if (isCharging == false) - { - MessageBox msgBox; - int outResult; - msgBox.Construct("Info", "Please Charge the Battery to use the recorder", MSGBOX_STYLE_OK, MESSAGE_BOX_TIMEOUT); - msgBox.ShowAndWait(outResult); - __pProgress->SetValue(0); - __pProgress->Draw(); - __pElapsedTimeLable->SetText(__startTime); - __pElapsedRecordSizeLable->SetText(__startSize); - - __pElapsedTimeLable->RequestRedraw(); - __pElapsedRecordSizeLable->RequestRedraw(); + MessageBox msgBox; + int outResult; + msgBox.Construct("Info", "Please Charge the Battery to use the recorder", MSGBOX_STYLE_OK, MESSAGE_BOX_TIMEOUT); + msgBox.ShowAndWait(outResult); - EnableFooterItem(ID_SETTING, false); - EnableFooterItem(ID_TOGGLE_CAMERA_TYPE, false); - EnableFooterItem(ID_START, false); - __batteryLevelFlag = true; + __pProgress->SetValue(0); + __pProgress->Draw(); + __pElapsedTimeLable->SetText(__startTime); + __pElapsedRecordSizeLable->SetText(__startSize); - //Free the resource and go back to previous form - FreeResources(); - Deactivate(); + __pElapsedTimeLable->RequestRedraw(); + __pElapsedRecordSizeLable->RequestRedraw(); + __batteryLevelFlag = true; - return E_SUCCESS; - } - else - { - EnableFooterItem(ID_SETTING, true); - EnableFooterItem(ID_START, true); - } + //Free the resource and go back to previous form + FreeResources(); + Deactivate(); + return E_SUCCESS; } else { EnableFooterItem(ID_SETTING, true); EnableFooterItem(ID_START, true); } + __batteryLevelFlag = false; __backGround = false; __cameraError = CAMERA_ERROR_NONE; @@ -1871,7 +1874,6 @@ VideoRecorderForm::OnActionPerformed(const Tizen::Ui::Control& source, int actio { case ID_BACK: { - TryReturnVoid(__pVideoRecorder != null, "__pVideoRecorder handle is null"); __pTimer->Cancel(); if (__pVideoRecorder->GetState() == RECORDER_STATE_RECORDING) @@ -1904,20 +1906,35 @@ VideoRecorderForm::OnActionPerformed(const Tizen::Ui::Control& source, int actio case ID_TOGGLE_CAMERA_TYPE: { - TryReturnVoid(__pVideoRecorder != null, "__pVideoRecorder handle is null"); - if (RECORDER_STATE_RECORDING != __pVideoRecorder->GetState()) + if (__pVideoRecorder != null) { - ShowFooterItem(0, false); - ShowFooterItem(1, false); - ShowFooterItem(2, false); - SendUserEvent(RECORDER_TOGGLE_CAMERA, null); + if (RECORDER_STATE_RECORDING != __pVideoRecorder->GetState()) + { + ShowFooterItem(0, false); + ShowFooterItem(1, false); + ShowFooterItem(2, false); + SendUserEvent(RECORDER_TOGGLE_CAMERA, null); + } + else + { + MessageBox msgBox; + int modalResult = 0; + msgBox.Construct(L"Error", L"Operation not allowed", MSGBOX_STYLE_NONE, 3000); + msgBox.ShowAndWait(modalResult); + } } else { - MessageBox msgBox; - int modalResult = 0; - msgBox.Construct(L"Error", L"Operation not allowed", MSGBOX_STYLE_NONE, 3000); - msgBox.ShowAndWait(modalResult); + if (IsBatteryLevelLow() == true) + { + MessageBox msgBox; + int outResult; + msgBox.Construct("Info", "Please Charge the Battery to use the recorder", MSGBOX_STYLE_OK, MESSAGE_BOX_TIMEOUT); + msgBox.ShowAndWait(outResult); + + FreeResources(); + Deactivate(); + } } } break; @@ -2210,6 +2227,19 @@ VideoRecorderForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collec { result r = E_SUCCESS; AppLog("VideoRecorderForm::OnUserEventReceivedN : request id = %d", requestId); + + if (IsBatteryLevelLow() == true) + { + MessageBox msgBox; + int outResult; + msgBox.Construct("Info", "Please Charge the Battery to use the recorder", MSGBOX_STYLE_OK, MESSAGE_BOX_TIMEOUT); + msgBox.ShowAndWait(outResult); + + FreeResources(); + Deactivate(); + return; + } + switch (requestId) { case RECORDER_START_STOP: diff --git a/project/src/Recorder/VideoRecorderForm.h b/project/src/Recorder/VideoRecorderForm.h index 6730e7b..157bd62 100644 --- a/project/src/Recorder/VideoRecorderForm.h +++ b/project/src/Recorder/VideoRecorderForm.h @@ -194,6 +194,8 @@ private: void ReadAudioPreProcessedFile(String fileName); bool ConvertPixelFormatToString(Tizen::Graphics::PixelFormat &pixFormat, String& strString); + bool IsBatteryLevelLow(void); + private: //Do not change the order of the e-nums, if a new e-num is to be added add it at the end enum