diff options
Diffstat (limited to 'project/src')
-rw-r--r-- | project/src/ImageForm.cpp | 341 | ||||
-rw-r--r-- | project/src/TiltableImageViewer.cpp | 86 | ||||
-rw-r--r-- | project/src/TiltableImageViewerEntry.cpp | 61 | ||||
-rw-r--r-- | project/src/TiltableImageViewerFrame.cpp | 52 |
4 files changed, 540 insertions, 0 deletions
diff --git a/project/src/ImageForm.cpp b/project/src/ImageForm.cpp new file mode 100644 index 0000000..322ac95 --- /dev/null +++ b/project/src/ImageForm.cpp @@ -0,0 +1,341 @@ +// +// Tizen C++ SDK +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Flora License, Version 1.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.tizenopensource.org/license +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include <new> +#include "ImageForm.h" + +using namespace Tizen::App; +using namespace Tizen::Ui; +using namespace Tizen::Uix::Sensor; +using namespace Tizen::Io; +using namespace Tizen::Media; +using namespace Tizen::Ui::Controls; +using namespace Tizen::Graphics; +using namespace Tizen::Base; +using namespace Tizen::Base::Runtime; +using namespace Tizen::System; + +static const int THIRD_QUADRANT_MIN = -150; +static const int THIRD_QUADRANT_MAX = -120; + +static const int FOURTH_QUADRANT_MIN = -60; +static const int FOURTH_QUADRANT_MAX = -30; + +static const int IMAGE_COUNT = 10; + +static const wchar_t IMAGE_EXT[] = L"jpg"; + +ImageForm::ImageForm(void) + : __sensorMgr() + , __dirBase() + , __fileList() + , __pImage(null) + , __pTimer(null) + , __fileIndex(0) + , __numFileList(0) + , __btCount(0) +{ + __fileList.Construct(); +} + +ImageForm::~ImageForm(void) +{ + __fileList.RemoveAll(true); +} + +result +ImageForm::OnDraw(void) +{ + String* nextImageName = static_cast<String*>(__fileList.GetAt(__fileIndex)); + + Bitmap* pBmp = __pImage->DecodeN(*nextImageName, BITMAP_PIXEL_FORMAT_ARGB8888); + TryReturn(pBmp != null, E_OUT_OF_MEMORY, "DecodeN failed! [srcImagePath:%ls]", nextImageName->GetPointer()); + + Canvas* pCanvas = GetCanvasN(); + if (pCanvas == null) + { + AppLogException("Get canvas failed."); + delete pBmp; + pBmp = null; + + return E_OUT_OF_MEMORY; + } + + Rectangle rect = GetClientAreaBounds(); + int boundWidth = rect.width; + rect.width /= 2; + rect.x = (boundWidth - rect.width) / 2; + + pCanvas->DrawBitmap(rect, *pBmp); + + delete pBmp; + pBmp = null; + delete pCanvas; + pCanvas = null; + + StartTimer(); + + return E_SUCCESS; +} + +bool +ImageForm::Initialize(void) +{ + Form::Construct(FORM_STYLE_NORMAL|FORM_STYLE_FOOTER|FORM_STYLE_HEADER|FORM_STYLE_INDICATOR); + SetName(L"TiltableImageViewer"); + + // Set Header title + Header* pHeader = this->GetHeader(); + pHeader->SetTitleText(L"TILTABLE IMAGE VIEWER"); + + Footer* pFooter = this->GetFooter(); + pFooter->SetStyle(FOOTER_STYLE_SEGMENTED_TEXT); + pFooter->SetBackButton(); + this->SetFormBackEventListener(this); + + return true; +} + +result +ImageForm::OnInitializing(void) +{ + SetOrientation(ORIENTATION_LANDSCAPE); + + SetBackgroundColor(Color::GetColor(COLOR_ID_WHITE)); + + __sensorMgr.Construct(); + + if(!__sensorMgr.IsAvailable(SENSOR_TYPE_TILT)) + { + AppLog("[Fail]TILT Sensor does not supported. This sample cannot be activated."); + + Application::GetInstance()->Terminate(); + + return E_FAILURE; + } + + result r = GetFileList(App::GetInstance()->GetAppRootPath() + String(L"res/")); + TryReturn(!IsFailed(r), r, "GetFileList failed! [result = %s]", GetErrorMessage(r)); + + r = InitializeTimer(); + TryReturn(!IsFailed(r), r, "Timer initialization failed"); + + __pImage = new (std::nothrow) Image(); + TryReturn(__pImage != null, E_OUT_OF_MEMORY, "Image creation failed"); + + __pImage->Construct(); + + long interval = 0; + + AppLog("Activating Tilt Sensor"); + __sensorMgr.GetMaxInterval(SENSOR_TYPE_TILT, interval); + + __sensorMgr.AddSensorListener(*this, SENSOR_TYPE_TILT, interval, false); + + StartTimer(); + + return r; +} + +result +ImageForm::OnTerminating(void) +{ + StopTimer(); + TerminateTimer(); + + if (__pImage != null) + { + delete __pImage; + __pImage = null; + } + + AppLog("Deactivating Tilt Sensor"); + __sensorMgr.RemoveSensorListener(*this); + + return E_SUCCESS; +} + +void +ImageForm::OnDataReceived(SensorType sensorType, SensorData& sensorData, result r) +{ + float pitch = 0.0F; + + sensorData.GetValue(static_cast<SensorDataKey>(TILT_DATA_KEY_PITCH), pitch); + //FIRST_QUADRANT : Quadrant I, MIN : Left boundary to get direction "left", MAX : Right boundary to get direction "left" + if (pitch >= THIRD_QUADRANT_MIN && pitch <= THIRD_QUADRANT_MAX) + { + __fileIndex--; + } + //FOURTH_QUADRANT : Quadrant IV, MIN : Left boundary to get direction "right", MAX : Right boundary to get direction "right" + else if (pitch >= FOURTH_QUADRANT_MIN && pitch <= FOURTH_QUADRANT_MAX) + { + __fileIndex++; + } + + AppLog("OnDataReceived: Get Tilt Sensor Data pitch[%f]", pitch); + + __fileIndex = (__fileIndex + __numFileList) % __numFileList; + __numFileList = __fileList.GetCount(); +} + + +/********************************************* + * Timer + *********************************************/ +result +ImageForm::InitializeTimer(void) +{ + __pTimer = new (std::nothrow) Timer(); + TryReturn(__pTimer != null, E_OUT_OF_MEMORY, "Timer creation failed"); + + __pTimer->Construct(*this); + + return E_SUCCESS; +} + +void +ImageForm::StartTimer(void) +{ + if (__pTimer != null) + { + __pTimer->Start(INTERVAL_TIMER); + } +} + +void +ImageForm::StopTimer(void) +{ + if (__pTimer != null) + { + __pTimer->Cancel(); + } +} + +void +ImageForm::TerminateTimer(void) +{ + if (__pTimer != null) + { + delete __pTimer; + __pTimer = null; + } +} + +void +ImageForm::OnTimerExpired(Timer & timer) +{ + this->RequestRedraw(true); +} + +result +ImageForm::GetFileList(String folder) +{ + result r = E_SUCCESS; + + __dirBase.Append(folder); + + String dirName(__dirBase); + Directory* pDir = new (std::nothrow) Directory(); + TryReturn(pDir != null, E_OUT_OF_MEMORY, "[Fail]Directory Create"); + + pDir->Construct(__dirBase); + + DirEnumerator* pDirEnum = pDir->ReadN(); + if (pDirEnum == null) + { + AppLog("IO Exception on Reading jpg image files"); + + delete pDir; + pDir = null; + return E_IO; + } + + while (pDirEnum->MoveNext() == E_SUCCESS) + { + DirEntry dirEntry = pDirEnum->GetCurrentDirEntry(); + AddElementInFileList(dirEntry, r); + } + + delete pDirEnum; + pDirEnum = null; + delete pDir; + pDir = null; + + TryReturn(__fileList.GetCount() == IMAGE_COUNT, E_IO, "Unexpected IO Exception"); + + String filename[IMAGE_COUNT]; + String* pTemp; + String subtemp; + int index = 0; + for (int i = 0; i < IMAGE_COUNT; i++) + { + pTemp = static_cast<String*>(__fileList.GetAt(i)); + pTemp->SubString(pTemp->GetLength() - 5, 1, subtemp); + Integer::Parse(subtemp, index); + filename[index] = *pTemp; + } + + __fileList.RemoveAll(true); + + for (int i = 0; i < IMAGE_COUNT; i++) + { + __fileList.Add(*(new (std::nothrow) String(filename[i]))); + } + + if (__fileList.GetCount() != IMAGE_COUNT) + { + __fileList.RemoveAll(true); + return E_IO; + } + + __numFileList = __fileList.GetCount(); + + return r; +} + +result +ImageForm::AddElementInFileList(DirEntry &DirEntry, result r) +{ + if (!DirEntry.IsDirectory()) + { + String ext(IMAGE_EXT); + String subStr; + String tempStr(__dirBase); + String fileName(DirEntry.GetName()); + + fileName.SubString(fileName.GetLength() - 3, 3, subStr); + if (subStr.Equals(ext, false)) + { + tempStr.Append(fileName); + + String* pNewString = new (std::nothrow) String(tempStr); + TryReturn(pNewString != null, E_OUT_OF_MEMORY, ""); + + __fileList.Add(*pNewString); + } + } + + return E_SUCCESS; +} + +void +ImageForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source) +{ + UiApp* pApp = UiApp::GetInstance(); + AppAssert(pApp); + pApp->Terminate(); +} diff --git a/project/src/TiltableImageViewer.cpp b/project/src/TiltableImageViewer.cpp new file mode 100644 index 0000000..6894042 --- /dev/null +++ b/project/src/TiltableImageViewer.cpp @@ -0,0 +1,86 @@ +// +// Tizen C++ SDK +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Flora License, Version 1.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.tizenopensource.org/license +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include <new> +#include "TiltableImageViewer.h" +#include "TiltableImageViewerFrame.h" + +#include "ImageForm.h" + +using namespace Tizen::App; +using namespace Tizen::Base; +using namespace Tizen::System; + +TiltableImageViewer::TiltableImageViewer(void) +{ +} + +TiltableImageViewer::~TiltableImageViewer(void) +{ +} + +Application* +TiltableImageViewer::CreateInstance(void) +{ + return new (std::nothrow) TiltableImageViewer(); +} + +bool +TiltableImageViewer::OnAppInitializing(AppRegistry& appRegistry) +{ + TiltableImageViewerFrame* pTiltableImageViewerFrame = new TiltableImageViewerFrame(); + + pTiltableImageViewerFrame->Construct(); + pTiltableImageViewerFrame->SetName(L"TiltableImageViewer"); + AddFrame(*pTiltableImageViewerFrame); + + + + + return true; +} + +bool +TiltableImageViewer::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination) +{ + return true; +} + +void +TiltableImageViewer::OnForeground(void) +{ +} + +void +TiltableImageViewer::OnBackground(void) +{ +} + +void +TiltableImageViewer::OnLowMemory(void) +{ +} + +void +TiltableImageViewer::OnScreenOn(void) +{ +} + +void +TiltableImageViewer::OnScreenOff(void) +{ +} diff --git a/project/src/TiltableImageViewerEntry.cpp b/project/src/TiltableImageViewerEntry.cpp new file mode 100644 index 0000000..b35be71 --- /dev/null +++ b/project/src/TiltableImageViewerEntry.cpp @@ -0,0 +1,61 @@ +// +// Tizen C++ SDK +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Flora License, Version 1.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.tizenopensource.org/license +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * This file contains the Tizen application entry point. + */ + +#include <new> +#include "TiltableImageViewer.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; + +#ifdef __cplusplus +extern "C" +{ +#endif // __cplusplus + +_EXPORT_ int OspMain(int argc, char *pArgv[]); + +/** + * The entry function of Tizen application called by the operating system. + */ +int +OspMain(int argc, char *pArgv[]) +{ + result r = E_SUCCESS; + + AppLog("Application started."); + ArrayList args; + args.Construct(); + for (int i = 0; i < argc; i++) + { + args.Add(*(new (std::nothrow) String(pArgv[i]))); + } + + r = Tizen::App::Application::Execute(TiltableImageViewer::CreateInstance, &args); + TryLog(r == E_SUCCESS, "[%s] Application execution failed", GetErrorMessage(r)); + + args.RemoveAll(true); + AppLog("Application finished."); + + return static_cast<int>(r); +} +#ifdef __cplusplus +} +#endif // __cplusplus diff --git a/project/src/TiltableImageViewerFrame.cpp b/project/src/TiltableImageViewerFrame.cpp new file mode 100644 index 0000000..df80d9b --- /dev/null +++ b/project/src/TiltableImageViewerFrame.cpp @@ -0,0 +1,52 @@ +#include "TiltableImageViewerFrame.h" +#include "ImageForm.h" + +using namespace Tizen::Base; +using namespace Tizen::Ui; +using namespace Tizen::Ui::Controls; + +TiltableImageViewerFrame::TiltableImageViewerFrame(void) +{ +} + +TiltableImageViewerFrame::~TiltableImageViewerFrame(void) +{ +} + +result +TiltableImageViewerFrame::OnInitializing(void) +{ + result r = E_SUCCESS; + + // Create a form + ImageForm *pImageForm = new (std::nothrow) ImageForm(); + pImageForm->Initialize(); + + // Add the form to the frame + AddControl(*pImageForm); + + // Set the current form + SetCurrentForm(*pImageForm); + + // Draw the form + pImageForm->Invalidate(true); + + // TODO: Add your initialization code here + + + + + return r; +} + +result +TiltableImageViewerFrame::OnTerminating(void) +{ + result r = E_SUCCESS; + + // TODO: Add your termination code here + + return r; +} + + |