public interface Animable {

    interface OnAnimationSetListener {
        void onAnimationSet(boolean success);
    }

    void animate(Animation a, OnAnimationSetListener l);

} public interface Colorable {

    interface OnColorChangedListener {
        void onColorSet(boolean success);
    }
    interface OnColorGetListener {
        void onColorGet(Integer c);
    }

    void changeColor(int c, OnColorChangedListener l);
    void setColor(int c, OnColorChangedListener l);
    void getColor(OnColorGetListener l);

} public interface HealthAware {

    interface OnHealthCheckListener {
        void onHealthCheck(boolean isHealthy);
    }

    void isHealthy(OnHealthCheckListener l);
} public interface PresetAware {

    interface OnPresetChangedListener {
        void onPresetChanged(boolean success);
    }
    interface OnPresetLoadedListener {
        void onPresetLoaded(Preset p);
    }
    List<Preset> getPresets();
    void setPreset(Preset p, OnPresetChangedListener l);
    void getPreset(OnPresetLoadedListener l);

} public interface Secured {

    interface OnValidityCheckedListener {
        void onValidityChecked(boolean valid);
    }

    void isValid(String key, OnValidityCheckedListener l);
} public interface Switchable {

    interface OnSwitchListener {
        void onActiveResult(Boolean isActive);
    }

    void isActive(OnSwitchListener l);
    void switchOn(OnSwitchListener l);
    void switchOff(OnSwitchListener l);
} public class AnimationSet {

    public final List<Animation> animations = new LinkedList<>();

    public AnimationSet animation(Animation a) {
        animations.add(a);
        return this;
    }

    public List<Animation> getAnimations() {
        return animations;
    }

    public List<String> queryString() {
        List<String> s = new ArrayList<>(animations.size());

        for (Animation a : animations) {
            s.add(new StringBuilder()
                    .append(a.r)
                    .append(",")
                    .append(a.g)
                    .append(",")
                    .append(a.b)
                    .append(",")
                    .append(a.loopTime)
                    .toString());
        }
        return s;
    }
} public interface LedStripService {
    @GET("api/status")
    Call<Status> getStatus(@Header("Authorization") String key);

    @POST("api/color")
    Call<ResponseBody> setColor(@Header("Authorization") String key, @Query("red") int red, @Query("green") int green, @Query("blue") int blue);

    @POST("api/color")
    Call<ResponseBody> changeColor(@Header("Authorization") String key, @Query("red") int red, @Query("green") int green, @Query("blue") int blue, @Query("hover") boolean hover);

    @POST("api/animate")
    Call<ResponseBody> setAnimation(@Header("Authorization") String key, @Query("red") int red, @Query("green") int green, @Query("blue") int blue, @Query("looptime") long loopTime);

    @POST("api/animate?type=2")
    Call<ResponseBody> setAnimation(@Header("Authorization") String key, @Query("step") List<String> steps);

    @POST("api/power")
    Call<ResponseBody> switchOnOff(@Header("Authorization") String key, @Query("power") int power);

    @GET("health")
    Call<ResponseBody> checkHealth(@Header("Authorization") String key);


} public class Animation {

    public int c;
    public long animationTime;

    public Animation(int c, long animationTime) {
        this.c = c;
        this.animationTime = animationTime;
    }
} public class Device {

    protected Long dbId;
    protected String id;
    protected int iconDrawable;
    protected String name;
    protected String host;
    protected String key;
    private DeviceTypeResolver resolver;

    public Device() {

    }

    public boolean supports(Class<? extends Command> clazz) {
        return resolver.supports(clazz);
    }

    public void setDbId(Long dbId) {
        this.dbId = dbId;
    }

    public Long getDbId() {
        return dbId;
    }

    public String getId() {
        return id;
    }

    public int getIconDrawable() {
        return iconDrawable;
    }

    public DeviceTypeResolver getResolver() {
        return resolver;
    }

    public <T> T getRemoteControl() {
        return (T) getResolver().getRemoteControl(this);
    }

    public String getName() {
        return name;
    }

    public String getHost() {
        return host;
    }

    public String getKey() {
        return key;
    }

    public void setId(String id) {
        this.id = id;
    }

    public void setIconDrawable(int iconDrawable) {
        this.iconDrawable = iconDrawable;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public void setResolver(DeviceTypeResolver resolver) {
        this.resolver = resolver;
    }

    @Override
    public String toString() {
        return "Device{" +
                "dbId=" + dbId +
                ", id='" + id + '\'' +
                ", iconDrawable=" + iconDrawable +
                ", name='" + name + '\'' +
                ", host='" + host + '\'' +
                ", key='" + key + '\'' +
                ", resolver=" + resolver +
                '}';
    }

    public static Builder builder() {
        return new Builder();
    }

    public static class Builder {

        private Device d;

        private Builder() {
            d = new Device();
            d.iconDrawable = R.drawable.default_bulb;
            d.name = "Device X";
        }

        public Builder id(String id) {
            d.id = id;
            return this;
        }

        public Builder dbId(Long id) {
            d.dbId = id;
            return this;
        }

        public Builder icon(int iconDrawable) {
            d.iconDrawable = iconDrawable;
            return this;
        }

        public Builder name(String name) {
            d.name = name;
            return this;
        }

        public Builder host(String host) {
            d.host = host;
            return this;
        }

        public Builder key(String key) {
            d.key = key;
            return this;
        }

        public Builder resolver(DeviceTypeResolver resolver) {
            d.resolver = resolver;
            return this;
        }

        public Device build() {
            return d;
        }
    }

} public class Preset {

    public int drawableResId;
    public int stringResId;
    public Object content;

    public Preset drawableResId(int resId) {
        this.drawableResId = resId;
        return this;
    }

    public Preset stringResId(int resId) {
        this.stringResId = resId;
        return this;
    }

    public Preset content(Object content) {
        this.content = content;
        return this;
    }

    public Preset addTo(Collection<Preset> c) {
        if (c != null) {
            c.add(this);
        }
        return this;
    }

}
import com.loicortola.controller.R;
import com.loicortola.controller.command.behavior.Animable;
import com.loicortola.controller.command.behavior.Colorable;
import com.loicortola.controller.command.behavior.HealthAware;
import com.loicortola.controller.command.behavior.PresetAware;
import com.loicortola.controller.command.behavior.Secured;
import com.loicortola.controller.command.behavior.Switchable;
import com.loicortola.controller.library.ledstrip.model.AnimationSet;
import com.loicortola.controller.library.ledstrip.service.LedStripService;
import com.loicortola.controller.model.Animation;
import com.loicortola.controller.model.Device;
import com.loicortola.controller.model.Preset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
package com.loicortola.controller.library.ledstrip.controller;



/**
 * Created by loic on 28/03/2016.
 */
public class LedStripRemoteControl implements Switchable, Colorable, Secured, Animable, HealthAware, PresetAware {

    private static final int GREY = 0x00888888;

    private Device d;
    private LedStripService service;