add launch app control for configuration code. show icon and preview
[apps/native/sample/DynamicBoxViewer.git] / project / src / LiveboxViewerMainForm.cpp
index 3198472..0216579 100644 (file)
@@ -16,6 +16,7 @@
 //
 
 #include <FApp.h>
+#include <FMedia.h>
 #include <FShellLiveboxProviderInfo.h>
 #include <FShellLiveboxManager.h>
 #include <FShellLiveboxSizeInfo.h>
@@ -32,6 +33,7 @@ using namespace Tizen::Ui::Controls;
 using namespace Tizen::Ui::Scenes;
 using namespace Tizen::Shell;
 
+const int LIST_ITEM_ICON = 72;
 const int LIST_ITEM_HEIGHT = 112;
 const int LIST_ITEM_MARGIN_LEFT = 26;
 const int LIST_ITEM_MARGIN_TOP = 32;
@@ -44,7 +46,18 @@ LiveboxViewerMainForm::LiveboxViewerMainForm(void)
        __pLiveboxProviderList = LiveboxManager::GetInstance()->GetLiveboxProviderInfoListN();
        TryReturnVoid(__pLiveboxProviderList, "GetLiveboxListN returns null!!" );
 
-       AppLog("All livebox count (%d)", __pLiveboxProviderList->GetCount() );
+       __pLiveboxIconList = new ArrayList(SingleObjectDeleter);
+       __pLiveboxIconList->Construct();
+       for( int i = 0; i < __pLiveboxProviderList->GetCount(); i++)
+       {
+               LiveboxProviderInfo* pLiveboxProviderInfo = dynamic_cast<LiveboxProviderInfo*>(__pLiveboxProviderList->GetAt(i) );
+
+               Tizen::Media::Image image;
+               result r = image.Construct();
+               Bitmap* pBmp = image.DecodeN(pLiveboxProviderInfo->GetIconPath(), BITMAP_PIXEL_FORMAT_ARGB8888);
+
+               __pLiveboxIconList->Add(pBmp);
+       }
 }
 
 LiveboxViewerMainForm::~LiveboxViewerMainForm(void)
@@ -114,6 +127,12 @@ LiveboxViewerMainForm::OnTerminating(void)
                delete __pLiveboxProviderList;
        }
 
+       if (__pLiveboxIconList)
+       {
+               __pLiveboxIconList->RemoveAll();
+               delete __pLiveboxIconList;
+       }
+
        return r;
 }
 
@@ -159,28 +178,54 @@ LiveboxViewerMainForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& curr
 void
 LiveboxViewerMainForm::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView &listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
 {
-       SceneManager* pSceneManager = SceneManager::GetInstance();
-       AppAssert(pSceneManager);
-
        if(status == LIST_ITEM_STATUS_SELECTED)
        {
-               ArrayList* pList = new (std::nothrow) ArrayList;
-               AppAssert(pList);
-               pList->Construct();
+               __pSelectedProviderInfo = dynamic_cast<LiveboxProviderInfo*>(__pLiveboxProviderList->GetAt(index));
+               AppAssert(__pSelectedProviderInfo);
 
-               LiveboxProviderInfo* pProviderInfo = dynamic_cast<LiveboxProviderInfo*>(__pLiveboxProviderList->GetAt(index));
-               AppAssert(pProviderInfo);
+               String configurationAppControlAppId = __pSelectedProviderInfo->GetConfigurationAppControlAppId();
+               if(!configurationAppControlAppId.IsEmpty())
+               {
+                       StartConfigurationAppControl(__pSelectedProviderInfo->GetConfigurationAppControlAppId(), __pSelectedProviderInfo->GetName());
+               }
+               else
+               {
+                       AppLog("%ls", __pSelectedProviderInfo->GetDisplayName().GetPointer());
+                       GoLiveboxViewScene(__pSelectedProviderInfo->GetAppId(), __pSelectedProviderInfo->GetName(), L"");
+               }
+       }
+}
 
-               AppLog("Display name (%ls)", pProviderInfo->GetDisplayName().GetPointer());
-               AppLog("AppId (%ls)", pProviderInfo->GetAppId().GetPointer());
-               AppLog("Name (%ls)", pProviderInfo->GetName().GetPointer());
+void
+LiveboxViewerMainForm::StartConfigurationAppControl(const Tizen::Base::String& appId, const Tizen::Base::String& providerName)
+{
+       AppControl* pAc = AppManager::FindAppControlN( appId, L"http://tizen.org/appcontrol/operation/livebox/configuration");
+       HashMap extra;
+       extra.Construct();
+       String key = L"ProviderName";
+       String value = providerName;
+       extra.Add(&key, &value);
+
+       pAc->Start(null, null, &extra, this);
+       delete pAc;
+}
 
-               pList->Add(*(new (std::nothrow) String( pProviderInfo->GetDisplayName())));
-               pList->Add(*(new (std::nothrow) String( pProviderInfo->GetAppId()) ));
-               pList->Add(*(new (std::nothrow) String( pProviderInfo->GetName()) ));
+void
+LiveboxViewerMainForm::GoLiveboxViewScene(const String& appId, const String& providerName, const String& userInfo)
+{
+       ArrayList* pList = new (std::nothrow) ArrayList;
+       AppAssert(pList);
+       pList->Construct();
 
-               pSceneManager->GoForward(ForwardSceneTransition(VIEW_SCENE, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pList);
-       }
+       pList->Add(*(new (std::nothrow) String(appId) ));
+       pList->Add(*(new (std::nothrow) String(providerName) ));
+       pList->Add(*(new (std::nothrow) String(userInfo )) );
+
+       SceneManager* pSceneManager = SceneManager::GetInstance();
+       AppAssert(pSceneManager);
+
+       pSceneManager->GoForward(ForwardSceneTransition(VIEW_SCENE, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pList);
+       __pSelectedProviderInfo = null;
 }
 
 void
@@ -207,21 +252,21 @@ LiveboxViewerMainForm::GetItemCount(void)
 Tizen::Ui::Controls::ListItemBase*
 LiveboxViewerMainForm::CreateItem (int index, int itemWidth)
 {
-       ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
-       
        CustomItem* pItem = new (std::nothrow) CustomItem();
-       pItem->Construct(Tizen::Graphics::Dimension(itemWidth, LIST_ITEM_HEIGHT), style);
+       pItem->Construct(Tizen::Graphics::Dimension(itemWidth, LIST_ITEM_HEIGHT), LIST_ANNEX_STYLE_NORMAL);
        
-       Rectangle itemRect(LIST_ITEM_MARGIN_LEFT, LIST_ITEM_MARGIN_TOP, GetClientAreaBounds().width - (LIST_ITEM_MARGIN_LEFT * 2), LIST_ITEM_TEXT_HEIGHT);
+       Rectangle iconRect(LIST_ITEM_MARGIN_LEFT, LIST_ITEM_MARGIN_TOP/2, LIST_ITEM_ICON, LIST_ITEM_ICON);
+       int text_x = LIST_ITEM_ICON + LIST_ITEM_MARGIN_LEFT + 20;
+       Rectangle textRect(text_x, LIST_ITEM_MARGIN_TOP, GetClientAreaBounds().width - LIST_ITEM_MARGIN_LEFT - text_x, LIST_ITEM_TEXT_HEIGHT);
        
        LiveboxProviderInfo* pProviderInfo = dynamic_cast<LiveboxProviderInfo*>(__pLiveboxProviderList->GetAt(index));
+
        if (pProviderInfo)
        {
-               String itemTitle(pProviderInfo->GetDisplayName());
-
-               AppLog("Item title (%ls)", itemTitle.GetPointer());
+               Bitmap* pBmp = dynamic_cast<Bitmap*>(__pLiveboxIconList->GetAt(index));
 
-               pItem->AddElement(itemRect, ID_FORMAT_STRING, itemTitle, true);
+               pItem->AddElement(iconRect, ID_FORMAT_BITMAP, *pBmp, null, null);
+               pItem->AddElement(textRect, ID_FORMAT_STRING, pProviderInfo->GetDisplayName()+" ("+pProviderInfo->GetAppId()+")", true);
        }
 
        return pItem;
@@ -233,3 +278,20 @@ LiveboxViewerMainForm::DeleteItem(int index, Tizen::Ui::Controls::ListItemBase *
        delete pItem;
        return true;
 }
+
+
+void
+LiveboxViewerMainForm::OnAppControlCompleteResponseReceived(const AppId& appId, const Tizen::Base::String& operationId, AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pExtraData)
+{
+       String temp;
+       TryReturnVoid(__pSelectedProviderInfo, "__pSelectedProviderInfo should not be null!");
+
+       if(pExtraData)
+       {
+               String userInfokey(L"UserInfo");
+               const String* pUserInfoValue = dynamic_cast<const String*>(pExtraData->GetValue(userInfokey) );
+               AppLog("%ls, %ls, %ls", appId.GetPointer(), operationId.GetPointer(), pUserInfoValue->GetPointer() );
+
+               GoLiveboxViewScene(__pSelectedProviderInfo->GetAppId(), __pSelectedProviderInfo->GetName(), *pUserInfoValue);
+       }
+}