alarms: show "vibration" icon on zero volume 14/93914/2
authorLukasz Stanislawski <l.stanislaws@samsung.com>
Mon, 24 Oct 2016 15:42:37 +0000 (17:42 +0200)
committerLukasz Stanislawski <l.stanislaws@samsung.com>
Wed, 26 Oct 2016 16:29:00 +0000 (18:29 +0200)
Change icon to vibration when user selects minimal
value with volume slider.
When more the minimal, show regular icon.

Change-Id: Id17a8f6730ea11abd43752c4385f136dfcd51b26

clock/inc/View/EditAlarmView.h
clock/res/images/01_volume_vibration.png [new file with mode: 0644]
clock/src/View/EditAlarmView.cpp

index f730008..8753130 100644 (file)
@@ -59,6 +59,7 @@ namespace view {
                        Evas_Object *left_btn_;
                        Evas_Object *right_btn_;
                        Evas_Object *main_radio_;
+                       Evas_Object *icon_slider_;
 
                        /* child view of EditAlarmView */
                        WeekFlagsView week_flags_view_;
@@ -71,6 +72,7 @@ namespace view {
                        Elm_Object_Item *volume_it_;
 
                        AlarmViewInfo data_;
+                       bool is_muted_;
 
                        static void OnCancelButtonClickedCb(void *data, Evas_Object *obj, void *event);
                        static void OnConfirmButtonClickedCb(void *data, Evas_Object *obj, void *event);
@@ -89,6 +91,8 @@ namespace view {
                        void CreateGenlistItems();
                        void ShowSetTypePopup();
                        void OnWeekFlagsPagePopped();
+
+                       void UpdateVolumeIcon(bool mute);
        };
 } /* view */
 
diff --git a/clock/res/images/01_volume_vibration.png b/clock/res/images/01_volume_vibration.png
new file mode 100644 (file)
index 0000000..42aa0d8
Binary files /dev/null and b/clock/res/images/01_volume_vibration.png differ
index 21d3ef7..11da0ce 100644 (file)
@@ -1,18 +1,22 @@
+#include "Utils/Log.h"
 #include "View/EditAlarmView.h"
 #include "Utils/Utils.h"
-#include <efl_extension.h>
 
+#include <efl_extension.h>
 #include <Elementary.h>
+#include <limits>
 
-#include "Utils/Log.h"
 
 using namespace view;
 using namespace utils;
 using namespace model;
 
 
+#define VIBRATION_ICON_PATH "images/01_volume_vibration.png"
+#define SOUND_ICON_PATH "images/00_volume_icon.png"
+
 EditAlarmView::EditAlarmView(ui::IView &main)
-       : PageView(main), week_flags_view_(main, data_.flags)
+       : PageView(main), week_flags_view_(main, data_.flags), is_muted_(false)
 {
        week_flags_view_.RegisterPoppedCallback(
                        std::bind(&EditAlarmView::OnWeekFlagsPagePopped, this));
@@ -153,6 +157,7 @@ void EditAlarmView::CreateContent(Evas_Object *parent)
        evas_object_size_hint_expand_set(content_, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
        evas_object_size_hint_align_set(content_, EVAS_HINT_FILL, EVAS_HINT_FILL);
        elm_genlist_mode_set(content_, ELM_LIST_COMPRESS);
+       elm_genlist_realization_mode_set(content_, EINA_TRUE);
        evas_object_show(content_);
 
        // fill created parts in object item
@@ -182,10 +187,48 @@ void EditAlarmView::DateTimeChangedCallback(void *data, Evas_Object *obj, void *
        }
 }
 
+void EditAlarmView::UpdateVolumeIcon(bool mute)
+{
+       const char *file_path;
+
+       if (!icon_slider_)
+               return;
+
+       // validate if any image is set
+       elm_icon_file_get(icon_slider_, &file_path, nullptr);
+       if (file_path && (is_muted_ == mute))
+               return;
+
+       if (mute) {
+               file_path = Utils::GetAppResourcePath(
+                                       Utils::APP_DIR_RESOURCE, VIBRATION_ICON_PATH);
+       } else {
+               file_path = Utils::GetAppResourcePath(
+                                       Utils::APP_DIR_RESOURCE, SOUND_ICON_PATH);
+       }
+       if (!elm_image_file_set(icon_slider_, file_path, nullptr)) {
+               FAT("elm_image_file_set failed");
+       }
+
+       is_muted_ = mute;
+}
+
 void EditAlarmView::SliderChangedCallback(void *data, Evas_Object *obj, void *event)
 {
+       double min;
+       bool mute;
        EditAlarmView *view = static_cast<EditAlarmView*>(data);
+
        view->data_.volume = elm_slider_value_get(obj);
+
+       elm_slider_min_max_get(obj, &min, nullptr);
+       if (fabs(view->data_.volume - min) < std::numeric_limits<double>::epsilon()) {
+               mute = true;
+       } else {
+               mute = false;
+       }
+
+       view->UpdateVolumeIcon(mute);
 }
 
 void EditAlarmView::CheckChangedCallback(void *data, Evas_Object *obj, void *event)
@@ -294,19 +337,22 @@ void EditAlarmView::CreateGenlistItems()
                if (!strcmp(part, "elm.swallow.slider")) {
                        Evas_Object *sldr = elm_slider_add(o);
                        elm_slider_min_max_set(sldr, 0.0, 1.0);
-                       elm_slider_value_set(sldr, view->data_.volume);
-                       evas_object_smart_callback_add(sldr, "delay,changed",
+                       evas_object_smart_callback_add(sldr, "changed",
                                        EditAlarmView::SliderChangedCallback, view);
+                       elm_slider_value_set(sldr, view->data_.volume);
                        evas_object_show(sldr);
                        return sldr;
                } else if (!strcmp(part, "elm.swallow.icon")) {
-                       Evas_Object *ic = elm_icon_add(o);
-                       evas_object_size_hint_expand_set(ic, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
-                       evas_object_size_hint_align_set(ic, EVAS_HINT_FILL, EVAS_HINT_FILL);
-                       elm_image_file_set(ic, Utils::GetAppResourcePath(
-                                               Utils::APP_DIR_RESOURCE, "images/00_volume_icon.png"), NULL);
-                       evas_object_show(ic);
-                       return ic;
+                       view->icon_slider_ = elm_icon_add(o);
+                       evas_object_size_hint_expand_set(view->icon_slider_, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+                       evas_object_size_hint_align_set(view->icon_slider_, EVAS_HINT_FILL, EVAS_HINT_FILL);
+                       if (view->data_.volume <= 0) {
+                               view->UpdateVolumeIcon(true);
+                       } else {
+                               view->UpdateVolumeIcon(false);
+                       }
+                       evas_object_show(view->icon_slider_);
+                       return view->icon_slider_;
                }
                return NULL;
        };
@@ -458,5 +504,6 @@ void EditAlarmView::OnWeekFlagsPagePopped(void)
 void EditAlarmView::SetData(const AlarmViewInfo &info)
 {
        data_ = info;
+       is_muted_ = data_.volume <= 0.0 ? true : false;
        elm_genlist_realized_items_update(content_);
 }