From 0584f759e92e80539e77c9bee24b4e63545cf37f Mon Sep 17 00:00:00 2001 From: Seema Date: Thu, 23 May 2013 16:36:29 +0530 Subject: [PATCH] Added check for low memory Change-Id: I009e0f82ea80e8950f1731f89c05f239c168f01a Signed-off-by: Seema --- inc/MmMemoApp.h | 1 + inc/MmTextEditorForm.h | 2 ++ src/MmDrawingDetailForm.cpp | 26 ++++++++++++++++++----- src/MmDrawingEditorForm.cpp | 31 ++++++++++++++++++++-------- src/MmMemoApp.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++--- src/MmTextEditorForm.cpp | 20 ++++++++++++++++++ 6 files changed, 114 insertions(+), 16 deletions(-) diff --git a/inc/MmMemoApp.h b/inc/MmMemoApp.h index cf71ef9..5732be5 100644 --- a/inc/MmMemoApp.h +++ b/inc/MmMemoApp.h @@ -51,6 +51,7 @@ public: virtual void OnSettingChanged(Tizen::Base::String& key); void SetAppControlLaunchedStatus(const bool launched); + long long GetMemoryStatus(void); private: MemoApp(void); virtual ~MemoApp(void); diff --git a/inc/MmTextEditorForm.h b/inc/MmTextEditorForm.h index d84a5b4..3817072 100644 --- a/inc/MmTextEditorForm.h +++ b/inc/MmTextEditorForm.h @@ -66,6 +66,8 @@ public: result OnInitializing(void); ///called while terminating the form result OnTerminating(void); + result OnDraw(void); + ///Reset all controls in Create form void RefreshCreateView(void); void RepositionControls(RepositionLabel newPosition); diff --git a/src/MmDrawingDetailForm.cpp b/src/MmDrawingDetailForm.cpp index 130b390..983e908 100644 --- a/src/MmDrawingDetailForm.cpp +++ b/src/MmDrawingDetailForm.cpp @@ -30,6 +30,7 @@ #include "MmTypes.h" #include "MmVMemoCreator.h" #include "MmThumbnailProvider.h" +#include "MmMemoApp.h" using namespace Tizen::Base; using namespace Tizen::Base::Collection; @@ -504,12 +505,27 @@ result MemoDrawingDetailForm::OnDraw(void) { result r = E_SUCCESS; - Canvas* pCanvas = GetCanvasN(__pCanvas->GetBounds().x, GetClientAreaBounds().y, __pCanvas->GetBounds().width, __pCanvas->GetBounds().height + __pDatetimePanel->GetBounds().height); - if (pCanvas != null) + long long mem = static_cast(MemoApp::CreateInstance())->GetMemoryStatus(); + if(mem <= 49999) { - pCanvas->Clear(); - pCanvas->Copy(Point(0, 0), *__pCanvas, Rectangle(0, 0,__pCanvas->GetBounds().width, __pCanvas->GetBounds().height + __pDatetimePanel->GetBounds().height)); - delete pCanvas; + int modal = ShowMessagePopUp(L"", GetResourceString(L"IDS_FM_POP_NOT_ENOUGH_STORAGE_SPACE"), MSGBOX_STYLE_OK, 0); + if(modal == MSGBOX_STYLE_OK) + { + SceneManager* pSceneManager = SceneManager::GetInstance(); + IList* pArgs = new (std::nothrow) ArrayList(); + pArgs->Add(new Integer(ID_REFRESH_LIST_FROM_LISTVIEW)); + pSceneManager->GoBackward(BackwardSceneTransition(IDSCN_MEMO_LIST), pArgs); + } + } + else + { + Canvas* pCanvas = GetCanvasN(__pCanvas->GetBounds().x, GetClientAreaBounds().y, __pCanvas->GetBounds().width, __pCanvas->GetBounds().height + __pDatetimePanel->GetBounds().height); + if (pCanvas != null) + { + pCanvas->Clear(); + pCanvas->Copy(Point(0, 0), *__pCanvas, Rectangle(0, 0,__pCanvas->GetBounds().width, __pCanvas->GetBounds().height + __pDatetimePanel->GetBounds().height)); + delete pCanvas; + } } return r; } diff --git a/src/MmDrawingEditorForm.cpp b/src/MmDrawingEditorForm.cpp index eca6282..10b209f 100644 --- a/src/MmDrawingEditorForm.cpp +++ b/src/MmDrawingEditorForm.cpp @@ -28,6 +28,7 @@ #include "MmInfo.h" #include "MmThumbnailProvider.h" #include "MmTypes.h" +#include "MmMemoApp.h" using namespace Tizen::App; using namespace Tizen::Base; @@ -249,16 +250,30 @@ result MemoDrawingEditorForm::OnDraw(void) { result r = E_SUCCESS; - Canvas* pCanvas = GetCanvasN(__pCanvas->GetBounds().x,GetClientAreaBounds().y + Y_CANVAS_AREA, __pCanvas->GetBounds().width, __pCanvas->GetBounds().height);//__pDrawingPanel->GetCanvasN(); - if (pCanvas != null) + long long mem = static_cast(MemoApp::CreateInstance())->GetMemoryStatus(); + if(mem <= 59999) { - r = pCanvas->Clear(); - r = pCanvas->Copy(Point(0,0),*__pCanvas, Rectangle(0, 0, __pCanvas->GetBounds().width, __pCanvas->GetBounds().height)); - pCanvas->SetBackgroundColor(Color::GetColor(COLOR_ID_WHITE)); - pCanvas->SetForegroundColor(Color::GetColor(COLOR_ID_BLACK)); - delete pCanvas; + int modal = ShowMessagePopUp(L"", GetResourceString(L"IDS_FM_POP_NOT_ENOUGH_STORAGE_SPACE"), MSGBOX_STYLE_OK, 0); + if(modal == MSGBOX_STYLE_OK) + { + SceneManager* pSceneManager = SceneManager::GetInstance(); + IList* pArgs = new (std::nothrow) ArrayList(); + pArgs->Add(new Integer(ID_REFRESH_LIST_FROM_LISTVIEW)); + pSceneManager->GoBackward(BackwardSceneTransition(IDSCN_MEMO_LIST), pArgs); + } + } + else + { + Canvas* pCanvas = GetCanvasN(__pCanvas->GetBounds().x,GetClientAreaBounds().y + Y_CANVAS_AREA, __pCanvas->GetBounds().width, __pCanvas->GetBounds().height);//__pDrawingPanel->GetCanvasN(); + if (pCanvas != null) + { + r = pCanvas->Clear(); + r = pCanvas->Copy(Point(0,0),*__pCanvas, Rectangle(0, 0, __pCanvas->GetBounds().width, __pCanvas->GetBounds().height)); + pCanvas->SetBackgroundColor(Color::GetColor(COLOR_ID_WHITE)); + pCanvas->SetForegroundColor(Color::GetColor(COLOR_ID_BLACK)); + delete pCanvas; + } } - // Do not call Show(). It will be called automatically after OnDraw() callback. return r; } diff --git a/src/MmMemoApp.cpp b/src/MmMemoApp.cpp index d485531..57a9069 100644 --- a/src/MmMemoApp.cpp +++ b/src/MmMemoApp.cpp @@ -68,7 +68,7 @@ MemoApp::OnAppInitialized(void) String languageSettingKey = L"http://tizen.org/setting/locale.language"; //Database initialization - MemoManager::GetInstance(); + MemoManager* pInstance = MemoManager::GetInstance(); MainFrame* pMainFrame = new (std::nothrow) MainFrame(); r = pMainFrame->Construct(); @@ -77,6 +77,32 @@ MemoApp::OnAppInitialized(void) AddFrame(*pMainFrame); SettingInfo::AddSettingEventListener(*this); SettingInfo::GetValue(languageSettingKey, __currentDisplayLanguage); + + //Database construct is failing in case of Low memory.hence terminate the app + if(pInstance == null) + { + int modal = ShowMessagePopUp(L"", GetResourceString(L"IDS_FM_POP_NOT_ENOUGH_STORAGE_SPACE"), Tizen::Ui::Controls::MSGBOX_STYLE_OK, 0); + if(modal == Tizen::Ui::Controls::MSGBOX_STYLE_OK) + { + SceneManager* pSceneManager = SceneManager::GetInstance(); + IList* pArgs = new (std::nothrow) ArrayList(); + pArgs->Add(new Integer(ID_REFRESH_LIST_FROM_LISTVIEW)); + pSceneManager->GoBackward(BackwardSceneTransition(IDSCN_MEMO_LIST), pArgs); + } + Application* pApp = Application::GetInstance(); + if(pApp != null) + { + pApp->Terminate(); + } + else + { + if(__pTheInstance != null) + { + __pTheInstance->Terminate(); + } + } + return true; + } return true; } @@ -86,8 +112,11 @@ MemoApp::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination) __isAppTerminating = true; MemoThumbnailProvider* __pThumbnailProvider = null; __pThumbnailProvider = MemoThumbnailProvider::GetInstance(); - __pThumbnailProvider->Stop(); - __pThumbnailProvider->Join(); + if(__pThumbnailProvider != null) + { + __pThumbnailProvider->Stop(); + __pThumbnailProvider->Join(); + } return true; } @@ -185,4 +214,19 @@ MemoApp::OnSettingChanged(Tizen::Base::String& key) pApp->Terminate(); } } + return; +} + +long long +MemoApp::GetMemoryStatus(void) +{ + String memoryKey = L"http://tizen.org/runtime/storage.available.internal"; + long long allocatedMemory = 0; + String memory; + result r = RuntimeInfo::GetValue(memoryKey, allocatedMemory); + if(r == E_SUCCESS) + { + memory.Append(allocatedMemory); + } + return allocatedMemory; } diff --git a/src/MmTextEditorForm.cpp b/src/MmTextEditorForm.cpp index 3ed09eb..2f04f96 100644 --- a/src/MmTextEditorForm.cpp +++ b/src/MmTextEditorForm.cpp @@ -26,6 +26,7 @@ #include "MmInfo.h" #include "MmTextEditorForm.h" #include "MmTypes.h" +#include "MmMemoApp.h" using namespace Tizen::App; using namespace Tizen::Base; @@ -414,6 +415,25 @@ MemoTextEditorForm::UpdateMemoInfo(void) return; } +result +MemoTextEditorForm::OnDraw(void) +{ + long long mem = static_cast(MemoApp::CreateInstance())->GetMemoryStatus(); + result r = E_SUCCESS; + if(mem <= 9999) + { + int modal = ShowMessagePopUp(L"", GetResourceString(L"IDS_FM_POP_NOT_ENOUGH_STORAGE_SPACE"), MSGBOX_STYLE_OK, 0); + if(modal == MSGBOX_STYLE_OK) + { + SceneManager* pSceneManager = SceneManager::GetInstance(); + IList* pArgs = new (std::nothrow) ArrayList(); + pArgs->Add(new Integer(ID_REFRESH_LIST_FROM_LISTVIEW)); + pSceneManager->GoBackward(BackwardSceneTransition(IDSCN_MEMO_LIST), pArgs); + } + } + return r; +} + void MemoTextEditorForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs) { -- 2.7.4