TizenRefApp-7983 Implement pick operation 61/113161/3
authorIryna Ferenchak <i.ferenchak@samsung.com>
Mon, 6 Feb 2017 12:30:55 +0000 (14:30 +0200)
committerIryna Ferenchak <i.ferenchak@samsung.com>
Mon, 6 Feb 2017 12:30:55 +0000 (14:30 +0200)
Change-Id: Id5309d2ef143e76bbfbb8d75592b8018eaa4f7a7
Signed-off-by: Iryna Ferenchak <i.ferenchak@samsung.com>
alarm-app/inc/OperationPickController.h [new file with mode: 0644]
alarm-app/src/AlarmApp.cpp
alarm-app/src/List/AlarmItem.cpp
alarm-app/src/List/AlarmsView.cpp
alarm-app/src/OperationPickController.cpp [new file with mode: 0644]
alarm-app/tizen-manifest.xml
alarm-widget/inc/AlarmWidget.h
alarm-widget/res/widget/edje/widget-layout.edc
alarm-widget/src/AlarmWidget.cpp
lib-common/inc/Common/Format.h
lib-common/src/Common/Format.cpp

diff --git a/alarm-app/inc/OperationPickController.h b/alarm-app/inc/OperationPickController.h
new file mode 100644 (file)
index 0000000..8f149ff
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.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.
+ */
+
+#ifndef OPERATION_PICK_CONTROLLER_H
+#define OPERATION_PICK_CONTROLLER_H
+
+#include "App/OperationController.h"
+#include "Ux/SelectTypes.h"
+
+class OperationPickController : public App::OperationController
+{
+private:
+       virtual void onRequest(const char *operation, app_control_h request) override;
+       bool onSelected(Ux::SelectResults results);
+};
+
+#endif /* OPERATION_PICK_CONTROLLER_H */
index 6e935cc457fb2c22e3c9ddb5b45cf544640846ca..a075cc31ca9f0af884c4175bf24ad026de7cf77e 100644 (file)
 #include "DaySelectorPath.h"
 #include "ListPath.h"
 #include "OperationDefaultController.h"
+#include "OperationPickController.h"
 
 App::OperationController *AlarmApp::createController(const char *operation)
 {
-       if (strcmp(operation, APP_CONTROL_OPERATION_DEFAULT) == 0
-        || strcmp(operation, APP_CONTROL_OPERATION_MAIN) == 0) {
+       if (strcmp(operation, APP_CONTROL_OPERATION_DEFAULT) == 0) {
                return new OperationDefaultController();
+       } else if (strcmp(operation, APP_CONTROL_OPERATION_PICK) == 0) {
+               return new OperationPickController();
        }
 
        return nullptr;
index e2a8e7652bb3b61036ae1d5ec82011ac368c31b8..3b4482ad324d38b6041c7bf2bfbfc6b1eb4fc3e4 100644 (file)
@@ -107,6 +107,11 @@ Evas_Object *AlarmItem::getContent(Evas_Object *parent, const char *part)
 
 void AlarmItem::onSelected()
 {
+       if (getSelectMode() != Ux::SelectNone) {
+               SelectItem::onSelected();
+               return;
+       }
+
        if (auto navigator = getParent()->findParent<Ui::Navigator>()) {
                navigator->navigateTo(new Input::InputView(m_Alarm));
        }
index 2dbf59ebd30a1b09716d10f3741d0dbd63fc9700..bb551d2bbb8b90aa6c42a8450675655cb6f37871 100644 (file)
@@ -84,6 +84,7 @@ AlarmItem *AlarmsView::createItem(::Model::DataItem &dataItem)
        auto item = new AlarmItem(static_cast<Alarm &>(dataItem));
        dataItem.onUpdated() += { std::bind(&AlarmsView::onAlarmUpdated, this, item, _1), item };
        dataItem.onDeleted() += { std::bind(&AlarmsView::onAlarmDeleted, this, item), item };
+       addSelectItem(item);
        return item;
 }
 
@@ -99,6 +100,7 @@ void AlarmsView::onAlarmUpdated(AlarmItem *item, int changes)
 
 void AlarmsView::onAlarmDeleted(AlarmItem *item)
 {
+       removeSelectItem(item);
        delete item;
 }
 
diff --git a/alarm-app/src/OperationPickController.cpp b/alarm-app/src/OperationPickController.cpp
new file mode 100644 (file)
index 0000000..c3d2d3d
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.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 "OperationPickController.h"
+#include "App/AppControl.h"
+#include "Common/Model/Alarm.h"
+#include "List/AlarmsView.h"
+#include "Ui/Navigator.h"
+#include <string>
+
+using namespace Common::Model;
+using namespace std::placeholders;
+
+void OperationPickController::onRequest(const char *operation, app_control_h request)
+{
+       List::AlarmsView *view = new List::AlarmsView();
+       view->setSelectMode(Ux::SelectSingle);
+       view->setSelectCallback(std::bind(&OperationPickController::onSelected, this, _1));
+       getNavigator()->navigateTo(view);
+}
+
+bool OperationPickController::onSelected(Ux::SelectResults results)
+{
+       auto alarm = (Alarm *)results.begin()->value.data;
+
+       app_control_h reply = nullptr;
+       app_control_create(&reply);
+       app_control_add_extra_data(reply, APP_CONTROL_DATA_SELECTED, std::to_string(alarm->getId()).c_str());
+       app_control_reply_to_launch_request(reply, getRequest(), APP_CONTROL_RESULT_SUCCEEDED);
+       app_control_destroy(reply);
+
+       return true;
+}
index 68e7cd12ad08d49ec3807db007dc9ac5c8fac322..ac5f45ff0ee18b13e91a2916befb9722a1576451 100644 (file)
         <label xml:lang="zh-tw">鬧鐘</label>
         <icon>org.tizen.alarm.png</icon>
     </ui-application>
+    <ui-application appid="org.tizen.alarm.app-control" exec="alarm-app" multiple="true" nodisplay="true" taskmanage="false" type="capp">
+        <label>Alarm</label>
+        <label xml:lang="ar-ae">تنبيه</label>
+        <label xml:lang="az-az">Siqnal</label>
+        <label xml:lang="bg-bg">Аларма</label>
+        <label xml:lang="ca-es">Alarma</label>
+        <label xml:lang="cs-cz">Upozornění</label>
+        <label xml:lang="da-dk">Alarm</label>
+        <label xml:lang="de-de">Alarm</label>
+        <label xml:lang="el-gr">Ξυπνητήρι</label>
+        <label xml:lang="en-gb">Alarm</label>
+        <label xml:lang="en-ph">Alarm</label>
+        <label xml:lang="en-us">Alarm</label>
+        <label xml:lang="es-es">Alarma</label>
+        <label xml:lang="es-mx">Alarma</label>
+        <label xml:lang="et-ee">Märguanne</label>
+        <label xml:lang="eu-es">Alarma</label>
+        <label xml:lang="fi-fi">Hälytys</label>
+        <label xml:lang="fr-ca">Alarme</label>
+        <label xml:lang="fr-fr">Alarme</label>
+        <label xml:lang="ga-ie">Aláram</label>
+        <label xml:lang="gl-es">Alarma</label>
+        <label xml:lang="hr-hr">Alarm</label>
+        <label xml:lang="hu-hu">Jelzés</label>
+        <label xml:lang="hy-am">Տագնապ</label>
+        <label xml:lang="is-is">Vekjari</label>
+        <label xml:lang="it-it">Sveglia</label>
+        <label xml:lang="ja-jp">アラーム</label>
+        <label xml:lang="ka-ge">სიგნალი</label>
+        <label xml:lang="kk-kz">Оятар</label>
+        <label xml:lang="ko-kr">알람</label>
+        <label xml:lang="lt-lt">Signalas</label>
+        <label xml:lang="lv-lv">Signāls</label>
+        <label xml:lang="mk-mk">Аларм</label>
+        <label xml:lang="nb-no">Alarm</label>
+        <label xml:lang="nl-nl">Alarm</label>
+        <label xml:lang="pl-pl">Alarm</label>
+        <label xml:lang="pt-br">Alarme</label>
+        <label xml:lang="pt-pt">Alarme</label>
+        <label xml:lang="ro-ro">Alarmă</label>
+        <label xml:lang="ru-ru">Будильник</label>
+        <label xml:lang="sk-sk">Budík</label>
+        <label xml:lang="sl-si">Alarm</label>
+        <label xml:lang="sr-rs">Beleška</label>
+        <label xml:lang="sv-se">Alarm</label>
+        <label xml:lang="tr-tr">Alarm</label>
+        <label xml:lang="uk-ua">Будильник</label>
+        <label xml:lang="uz-uz">Uyg‘otgich</label>
+        <label xml:lang="zh-cn">闹钟</label>
+        <label xml:lang="zh-hk">鬧鐘</label>
+        <label xml:lang="zh-tw">鬧鐘</label>
+        <icon>org.tizen.alarm.png</icon>
+        <app-control>
+            <operation name="http://tizen.org/appcontrol/operation/pick"/>
+            <mime name="application/vnd.tizen.alarm"/>
+        </app-control>
+    </ui-application>
     <privileges>
         <privilege>http://tizen.org/privilege/datasharing</privilege>
     </privileges>
index 94e56c8a46c763d75c1073c7d83c3421ccf54330..1f53d82625516bafddd0c938801c0e98a0bd387b 100644 (file)
@@ -43,8 +43,11 @@ private:
        Evas_Object *createContentLayout(Evas_Object *parent);
        Evas_Object *createEmptyLayout(Evas_Object *parent);
        void updateEmptyState();
+       void onCheckedPressed(Evas_Object *obj, void *eventInfo);
        void onCreatePressed(Evas_Object *obj, void *eventInfo);
 
+       void onPickReply(app_control_h request, app_control_h reply, app_control_result_e result);
+
        Evas_Object *m_Layout;
        Common::Model::Alarm *m_Alarm;
 };
index 7701cea02de6493d3d85ca24d7737689daa7bdc3..f92a79867f065cff5bc9c1b6d8cd6453d4c2677e 100644 (file)
 #define TEXT_NO_ALARM_H     42
 #define TEXT_NO_ALARM_T     16
 
-#define TIME_L              62
 #define TIME_T              59
-#define TIME_W              244
 #define TIME_H              95
 
 #define REPEAT_T            8
-#define REPEAT_L            90
-#define REPEAT_W            180
 #define REPEAT_H            41
 
 #define ON_OFF_T            221
@@ -48,12 +44,10 @@ styles {
        style {
                name: "time_style";
                base: "font=Tizen:style=Thin font_size=79 align=center color=#ffffff ellipsis=-1.0";
-               tag: "match" "+font_size=40 font=Tizen:style=Regular";
        }
        style {
                name: "time_disabled_style";
                base: "font=Tizen:style=Thin font_size=79 align=center color=#ffffff4C ellipsis=-1.0";
-               tag: "match" "+font_size=40 font=Tizen:style=Regular";
        }
        style {
                name: "repeat_style";
@@ -157,21 +151,21 @@ collections {
 
        group { LAYOUT_ALARM;
                parts {
-                       spacer { "spacer.time.left_top"; scale;
+                       spacer { "spacer.time.top"; scale;
                                desc { "default";
-                                       fixed: 1 1;
-                                       min: TIME_L TIME_T;
-                                       align: 0.0 0.0;
-                                       rel2.relative: 0.0 0.0;
+                                       fixed: 0 1;
+                                       min: 0 TIME_T;
+                                       align: 0.5 0.0;
+                                       rel2.relative: 1.0 0.0;
                                }
                        }
                        textblock { PART_TIME; scale;
                                desc { "default";
-                                       fixed: 1 1;
-                                       min: TIME_W TIME_H;
-                                       align: 0.0 0.0;
-                                       rel1 { relative: 1.0 1.0; to: "spacer.time.left_top"; }
-                                       rel2 { relative: 1.0 1.0; to: "spacer.time.left_top"; }
+                                       fixed: 0 1;
+                                       min: 0 TIME_H;
+                                       align: 0.5 0.0;
+                                       rel1 { relative: 0.0 1.0; to_y: "spacer.time.top"; }
+                                       rel2 { relative: 1.0 1.0; to_y: "spacer.time.top"; }
                                        text.style: "time_style";
                                }
                                desc { "disabled";
@@ -179,22 +173,22 @@ collections {
                                        text.style: "time_disabled_style";
                                }
                        }
-                       spacer { "spacer.repeat.left_top"; scale;
+                       spacer { "spacer.repeat.top"; scale;
                                desc { "default";
-                                       fixed: 1 1;
-                                       min: REPEAT_L REPEAT_T;
-                                       align: 0.0 1.0;
+                                       fixed: 0 1;
+                                       min: 0 REPEAT_T;
+                                       align: 0.5 1.0;
                                        rel1 { relative: 0.0 1.0; to_y: PART_TIME; }
-                                       rel2 { relative: 0.0 1.0; to_y: PART_TIME; }
+                                       rel2 { relative: 1.0 1.0; to_y: PART_TIME; }
                                }
                        }
                        textblock { PART_REPEAT; scale;
                                desc { "default";
-                                       fixed: 1 1;
-                                       min: REPEAT_W REPEAT_H;
-                                       align: 0.0 0.0;
-                                       rel1 { relative: 1.0 0.0; to: "spacer.repeat.left_top"; }
-                                       rel2 { relative: 1.0 0.0; to: "spacer.repeat.left_top"; }
+                                       fixed: 0 1;
+                                       min: 0 REPEAT_H;
+                                       align: 0.5 0.0;
+                                       rel1 { relative: 0.0 1.0; to_y: "spacer.repeat.top"; }
+                                       rel2 { relative: 1.0 1.0; to_y: "spacer.repeat.top"; }
                                        text.style: "repeat_style";
                                }
                                desc { "disabled";
index 21edd9a1ebfc339b5d53889cb0afb38d257d808e..506ed8635fe6a555b5583db18f7381c48e39a38c 100644 (file)
  */
 
 #include "AlarmWidget.h"
+#include "App/AppControl.h"
+#include "App/AppControlUtils.h"
 #include "App/Path.h"
+#include "Common/Format.h"
 #include "Common/Model/Alarm.h"
+#include "Common/Model/AlarmConsumer.h"
 #include "Ui/Window.h"
 #include "Utils/Callback.h"
 #include "Utils/Logger.h"
 
 #include "CommonPath.h"
 #include "WidgetLayout.h"
-
-#define TAG_PREFIX "<match>"
-#define TAG_SUFFIX "</match>"
+#include <stdlib.h>
 
 using namespace Model;
 using namespace Common;
 using namespace Common::Model;
 
+#define TIME_SIZE  40
+#define APP_CONTROL_MIME_ALARM "application/vnd.tizen.alarm"
+
 AlarmWidget::AlarmWidget()
        : m_Layout(nullptr), m_Alarm(nullptr)
 {
@@ -48,6 +53,15 @@ Evas_Object *AlarmWidget::createContentLayout(Evas_Object *parent)
        Evas_Object *layout = elm_layout_add(parent);
        elm_layout_file_set(layout, App::getResourcePath(PATH_WIDGET_LAYOUT).c_str(), LAYOUT_ALARM);
 
+       elm_object_part_text_set(layout, PART_TIME, formatTime(m_Alarm->getDate(), TIME_SIZE));
+       elm_object_part_text_set(layout, PART_REPEAT, formatRepeat(m_Alarm->getRepeat()));
+
+       Evas_Object *check = elm_check_add(layout);
+       elm_check_state_set(check, m_Alarm->isEnabled());
+       elm_object_style_set(check, STYLE_CHECK_ALARM_ON_OFF);
+       elm_object_part_content_set(layout, PART_ON_OFF, check);
+       evas_object_smart_callback_add(check, "changed", makeCallback(&AlarmWidget::onCheckedPressed), this);
+
        return layout;
 }
 
@@ -75,6 +89,23 @@ void AlarmWidget::updateEmptyState()
        elm_object_part_content_set(parent, "elm.swallow.content", m_Layout);
 }
 
+void AlarmWidget::onCheckedPressed(Evas_Object *obj, void *eventInfo)
+{
+       /* TODO add implementation */
+}
+
 void AlarmWidget::onCreatePressed(Evas_Object *obj, void *eventInfo)
 {
+       App::AppControl request(APP_CONTROL_OPERATION_PICK, APP_CONTROL_MIME_ALARM);
+       request.launch(makeCallbackWithLastParam(&AlarmWidget::onPickReply), this);
+       request.detach();
+}
+
+void AlarmWidget::onPickReply(app_control_h request, app_control_h reply, app_control_result_e result)
+{
+       std::string path = App::getStringExtraData(reply, APP_CONTROL_DATA_SELECTED);
+       AlarmConsumer::getInstance().getAlarm(atoi(path.c_str()), [this](::Model::DataProvider::DataList dataList) {
+               m_Alarm = static_cast<Alarm *>(dataList.front());
+               updateEmptyState();
+       });
 }
index 137f022e56592bf1f5fd490173a8a878853ce408..b36d6811721e6ce6bca9c688633ca26e73377db1 100644 (file)
@@ -37,9 +37,10 @@ namespace Common
         * @brief Create string representation for given time.
         * @param[in]   time        Time to format
         * @param[in]   fontSize    Font size for AM/PM representation
+        * @param[in]   fontStyle   Font style for AM/PM representation
         * @return Formatted time.
         */
-       EXPORT_API const char *formatTime(const tm &time, int fontSize);
+       EXPORT_API const char *formatTime(const tm &time, int fontSize, const char *fontStyle = "Regular");
 
        /**
         * @brief Create string representation for given date.
index 84a52cc65b8470804e5fa543a3d5b5a1cfd068b2..ea725336a2da173c86b0d646f6894ccd7eca68af 100644 (file)
@@ -54,14 +54,14 @@ bool Common::is24HourFormat()
        return is24hour;
 }
 
-const char *Common::formatTime(const tm &time, int fontSize)
+const char *Common::formatTime(const tm &time, int fontSize, const char *fontStyle)
 {
        static char buffer[TIME_BUFFER_SIZE];
        if (is24HourFormat()) {
                strftime(buffer, sizeof(buffer), "%H:%M", &time);
        } else {
                char format[TIME_BUFFER_SIZE];
-               snprintf(format, sizeof(format), "%%I:%%M <font_size=%d>%%p</font_size>", fontSize);
+               snprintf(format, sizeof(format), "%%I:%%M<font=Tizen:style=%s font_size=%d> %%p</font>", fontStyle, fontSize);
                strftime(buffer, sizeof(buffer), format, &time);
        }