Commit 648f81cc authored by Ludovic Fauvet's avatar Ludovic Fauvet

video player: add volume gestures

parent fe9fb527
......@@ -79,6 +79,10 @@
#include <Evas.h>
// Non-type aware!
#define MAX(a,b) ((a) > (b) ? a : b)
#define MIN(a,b) ((a) < (b) ? a : b)
#define MAX_LENGTH_PATH 1024
static inline const char *get_resource_path(const char *file_path)
{
......
......@@ -55,6 +55,18 @@ collections
}
}
}
part {
name: "gesturerect";
type: SWALLOW;
description {
rel1 {
relative: 0.0 0.0;
}
rel2 {
relative: 1.0 1.0;
}
}
}
part{
name: "hub_background";
type: RECT;
......
......@@ -29,6 +29,7 @@
#include <Elementary.h>
#include <Emotion.h>
#include <efl_extension.h>
#include <sound_manager.h>
#include "ui/interface.h"
#include "ui/utils.h"
......@@ -56,6 +57,11 @@ struct view_sys
Evas_Object *lock_button, *more_button;
Evas_Object *p_current_popup;
/* Gestures */
bool gesture_volume;
int display_distance;
int base_volume;
};
static void video_player_stop(view_sys *p_sys);
......@@ -439,6 +445,85 @@ video_player_stop(view_sys *p_sys)
}
}
static Evas_Event_Flags
line_start(void *data, void *event_info)
{
Elm_Gesture_Line_Info *p = (Elm_Gesture_Line_Info *) event_info;
LOGD("line started angle=<%lf> x1,y1=<%d,%d> x2,y2=<%d,%d> tx,ty=<%u,%u> n=<%u>",
p->angle, p->momentum.x1, p->momentum.y1, p->momentum.x2, p->momentum.y2,
p->momentum.tx, p->momentum.ty, p->momentum.n);
view_sys *p_sys = data;
if (p->momentum.n == 1 && (p->angle > 315 || p->angle < 45 || (p->angle > 135 && p->angle < 225)))
{
if (sound_manager_get_volume(SOUND_TYPE_MEDIA, &p_sys->base_volume) != 0)
{
LOGE("Unable to get the volume.");
return EVAS_EVENT_FLAG_ON_HOLD;
}
int w, h;
evas_object_geometry_get(p_sys->layout, NULL, NULL, &w, &h);
p_sys->display_distance = MIN(w, h);
if (p_sys->display_distance == 0)
return EVAS_EVENT_FLAG_ON_HOLD;
p_sys->gesture_volume = true;
}
return EVAS_EVENT_FLAG_ON_HOLD;
}
static Evas_Event_Flags
line_move(void *data, void *event_info)
{
Elm_Gesture_Line_Info *p = (Elm_Gesture_Line_Info *) event_info;
view_sys *p_sys = data;
if (p_sys->gesture_volume == true)
{
int max;
if (sound_manager_get_max_volume(SOUND_TYPE_MEDIA, &max) != 0)
return EVAS_EVENT_FLAG_ON_HOLD;
int step = p_sys->display_distance / max;
int diff = p->momentum.y1 - p->momentum.y2;
int volume = MIN(MAX(0, p_sys->base_volume + (diff / step)), max);
sound_manager_set_volume(SOUND_TYPE_MEDIA, volume);
LOGD("Volume: %d (max %d)", volume, max);
}
return EVAS_EVENT_FLAG_ON_HOLD;
}
static Evas_Event_Flags
line_end(void *data, void *event_info)
{
Elm_Gesture_Line_Info *p = (Elm_Gesture_Line_Info *) event_info;
LOGD("line end angle=<%lf> x1,y1=<%d,%d> x2,y2=<%d,%d> tx,ty=<%u,%u> n=<%u>",
p->angle, p->momentum.x1, p->momentum.y1, p->momentum.x2, p->momentum.y2,
p->momentum.tx, p->momentum.ty, p->momentum.n);
view_sys *p_sys = data;
p_sys->gesture_volume = false;
return EVAS_EVENT_FLAG_ON_HOLD;
}
static Evas_Event_Flags
line_abort(void *data, void *event_info)
{
view_sys *p_sys = data;
LOGD("line abort");
p_sys->gesture_volume = false;
return EVAS_EVENT_FLAG_ON_HOLD;
}
Evas_Object*
video_player_create_ui(view_sys *p_sys, Evas_Object *parent)
{
......@@ -457,6 +542,26 @@ video_player_create_ui(view_sys *p_sys, Evas_Object *parent)
emotion_object_keep_aspect_set(p_sys->p_evas_video, EMOTION_ASPECT_KEEP_BOTH);
evas_object_show(p_sys->p_evas_video);
/* Create the gesture layer */
Evas_Object *r = evas_object_rectangle_add(layout);
evas_object_color_set(r, 0, 0, 0, 0);
elm_object_part_content_set(layout, "gesturerect", r);
Evas_Object *g = elm_gesture_layer_add(layout);
elm_gesture_layer_attach(g, r);
evas_object_show(r);
elm_gesture_layer_continues_enable_set(g, EINA_FALSE);
elm_gesture_layer_cb_set(g, ELM_GESTURE_N_LINES, ELM_GESTURE_STATE_START,
line_start, p_sys);
elm_gesture_layer_cb_set(g, ELM_GESTURE_N_LINES, ELM_GESTURE_STATE_MOVE,
line_move, p_sys);
elm_gesture_layer_cb_set(g, ELM_GESTURE_N_LINES, ELM_GESTURE_STATE_END,
line_end, p_sys);
elm_gesture_layer_cb_set(g, ELM_GESTURE_N_LINES, ELM_GESTURE_STATE_ABORT,
line_abort, p_sys);
/* create play/pause button */
p_sys->play_pause_button = elm_image_add(layout);
elm_image_file_set(p_sys->play_pause_button, ICON_DIR"ic_pause_circle_normal_o.png", NULL);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment