+#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));
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
}
}
+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)
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;
};
void EditAlarmView::SetData(const AlarmViewInfo &info)
{
data_ = info;
+ is_muted_ = data_.volume <= 0.0 ? true : false;
elm_genlist_realized_items_update(content_);
}