Android Open Source - blink Scene Device






From Project

Back to project page blink.

License

The source code is released under:

Apache License

If you think the Android project blink listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.nashlincoln.blink.model;
//from  w  ww  .j a v a 2s  .com
import java.util.List;
import com.nashlincoln.blink.model.DaoSession;
import de.greenrobot.dao.DaoException;

// THIS CODE IS GENERATED BY greenDAO, EDIT ONLY INSIDE THE "KEEP"-SECTIONS

// KEEP INCLUDES - put your custom includes here
import com.nashlincoln.blink.app.BlinkApp;
// KEEP INCLUDES END
/**
 * Entity mapped to table SCENE_DEVICE.
 */
public class SceneDevice {

    private Long id;
    private Long sceneId;
    private Long deviceId;
    private String attributableType;

    /** Used to resolve relations */
    private transient DaoSession daoSession;

    /** Used for active entity operations. */
    private transient SceneDeviceDao myDao;

    private Scene scene;
    private Long scene__resolvedKey;

    private Device device;
    private Long device__resolvedKey;

    private List<Attribute> attributes;

    // KEEP FIELDS - put your custom fields here
    private static final String ATTRIBUTABLE_TYPE = "Scene";
    // KEEP FIELDS END

    public SceneDevice() {
    }

    public SceneDevice(Long id) {
        this.id = id;
    }

    public SceneDevice(Long id, Long sceneId, Long deviceId, String attributableType) {
        this.id = id;
        this.sceneId = sceneId;
        this.deviceId = deviceId;
        this.attributableType = attributableType;
    }

    /** called by internal mechanisms, do not call yourself. */
    public void __setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
        myDao = daoSession != null ? daoSession.getSceneDeviceDao() : null;
    }

    public Long getId() {
        return id;
    }

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

    public Long getSceneId() {
        return sceneId;
    }

    public void setSceneId(Long sceneId) {
        this.sceneId = sceneId;
    }

    public Long getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(Long deviceId) {
        this.deviceId = deviceId;
    }

    public String getAttributableType() {
        return attributableType;
    }

    public void setAttributableType(String attributableType) {
        this.attributableType = attributableType;
    }

    /** To-one relationship, resolved on first access. */
    public Scene getScene() {
        Long __key = this.sceneId;
        if (scene__resolvedKey == null || !scene__resolvedKey.equals(__key)) {
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            SceneDao targetDao = daoSession.getSceneDao();
            Scene sceneNew = targetDao.load(__key);
            synchronized (this) {
                scene = sceneNew;
              scene__resolvedKey = __key;
            }
        }
        return scene;
    }

    public void setScene(Scene scene) {
        synchronized (this) {
            this.scene = scene;
            sceneId = scene == null ? null : scene.getId();
            scene__resolvedKey = sceneId;
        }
    }

    /** To-one relationship, resolved on first access. */
    public Device getDevice() {
        Long __key = this.deviceId;
        if (device__resolvedKey == null || !device__resolvedKey.equals(__key)) {
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            DeviceDao targetDao = daoSession.getDeviceDao();
            Device deviceNew = targetDao.load(__key);
            synchronized (this) {
                device = deviceNew;
              device__resolvedKey = __key;
            }
        }
        return device;
    }

    public void setDevice(Device device) {
        synchronized (this) {
            this.device = device;
            deviceId = device == null ? null : device.getId();
            device__resolvedKey = deviceId;
        }
    }

    /** To-many relationship, resolved on first access (and after reset). Changes to to-many relations are not persisted, make changes to the target entity. */
    public List<Attribute> getAttributes() {
        if (attributes == null) {
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            AttributeDao targetDao = daoSession.getAttributeDao();
            List<Attribute> attributesNew = targetDao._querySceneDevice_Attributes(id, attributableType);
            synchronized (this) {
                if(attributes == null) {
                    attributes = attributesNew;
                }
            }
        }
        return attributes;
    }

    /** Resets a to-many relationship, making the next get call to query for a fresh result. */
    public synchronized void resetAttributes() {
        attributes = null;
    }

    /** Convenient call for {@link AbstractDao#delete(Object)}. Entity must attached to an entity context. */
    public void delete() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }    
        myDao.delete(this);
    }

    /** Convenient call for {@link AbstractDao#update(Object)}. Entity must attached to an entity context. */
    public void update() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }    
        myDao.update(this);
    }

    /** Convenient call for {@link AbstractDao#refresh(Object)}. Entity must attached to an entity context. */
    public void refresh() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }    
        myDao.refresh(this);
    }

    // KEEP METHODS - put your custom methods here

    public void copyAttributes(final List<Attribute> attributes) {
        BlinkApp.getDaoSession().runInTx(new Runnable() {
            @Override
            public void run() {
                AttributeDao attributeDao = BlinkApp.getDaoSession().getAttributeDao();
                for (Attribute attribute : attributes) {
                    Attribute attr = new Attribute();
                    attr.setAttributableType(ATTRIBUTABLE_TYPE);
                    attr.setAttributableId(getId());
                    attr.setAttributeType(attribute.getAttributeType());
                    attr.setValue(attribute.getValue());
                    attributeDao.insert(attr);
                    getAttributes().add(attr);
                }
                resetAttributes();
            }
        });
    }

    public void setLevel(final int level) {
        Attribute attribute = getAttributes().get(1);
        attribute.setValue(String.valueOf(level));
        attribute.update();
    }

    public void setOn(final boolean on) {
        Attribute attribute = getAttributes().get(0);
        attribute.setValue(on ? Attribute.ON : Attribute.OFF);
        attribute.update();
    }

    public boolean isOn() {
        return getAttributes().get(0).getBool();
    }

    public int getLevel() {
        return getAttributes().get(1).getInt();
    }

    public static SceneDevice newInstance() {
        SceneDevice sceneDevice = new SceneDevice();
        sceneDevice.setAttributableType(ATTRIBUTABLE_TYPE);
        return sceneDevice;
    }

    public void deleteWithReferences() {
        for (Attribute attribute : getAttributes()) {
            attribute.delete();
        }
        delete();
    }
    // KEEP METHODS END

}




Java Source Code List

com.nashlincoln.blink.ApplicationTest.java
com.nashlincoln.blink.app.BlinkApp.java
com.nashlincoln.blink.app.FragmentPagerAdapter.java
com.nashlincoln.blink.app.NetworkReceiver.java
com.nashlincoln.blink.app.PreferenceUtils.java
com.nashlincoln.blink.content.Command.java
com.nashlincoln.blink.content.DeviceLoader.java
com.nashlincoln.blink.content.DeviceTypeLoader.java
com.nashlincoln.blink.content.GroupLoader.java
com.nashlincoln.blink.content.ModelLoader.java
com.nashlincoln.blink.content.SceneLoader.java
com.nashlincoln.blink.content.Syncro.java
com.nashlincoln.blink.event.Event.java
com.nashlincoln.blink.event.Status.java
com.nashlincoln.blink.event.Type.java
com.nashlincoln.blink.model.AttributeDao.java
com.nashlincoln.blink.model.AttributeTypeDao.java
com.nashlincoln.blink.model.AttributeType.java
com.nashlincoln.blink.model.Attribute.java
com.nashlincoln.blink.model.DaoMaster.java
com.nashlincoln.blink.model.DaoSession.java
com.nashlincoln.blink.model.DeviceDao.java
com.nashlincoln.blink.model.DeviceTypeDao.java
com.nashlincoln.blink.model.DeviceType.java
com.nashlincoln.blink.model.Device.java
com.nashlincoln.blink.model.GroupDao.java
com.nashlincoln.blink.model.GroupDeviceDao.java
com.nashlincoln.blink.model.GroupDevice.java
com.nashlincoln.blink.model.Group.java
com.nashlincoln.blink.model.SceneDao.java
com.nashlincoln.blink.model.SceneDeviceDao.java
com.nashlincoln.blink.model.SceneDevice.java
com.nashlincoln.blink.model.Scene.java
com.nashlincoln.blink.model.TimerDao.java
com.nashlincoln.blink.model.Timer.java
com.nashlincoln.blink.network.BlinkApiInterface.java
com.nashlincoln.blink.network.BlinkApi.java
com.nashlincoln.blink.nfc.NfcCommand.java
com.nashlincoln.blink.nfc.NfcUtils.java
com.nashlincoln.blink.ui.AddDeviceFragment.java
com.nashlincoln.blink.ui.BlinkActivity.java
com.nashlincoln.blink.ui.BlinkListFragment.java
com.nashlincoln.blink.ui.DeviceListFragment.java
com.nashlincoln.blink.ui.EditListActivity.java
com.nashlincoln.blink.ui.EditListFragment.java
com.nashlincoln.blink.ui.EditNameDialogFragment.java
com.nashlincoln.blink.ui.GroupListFragment.java
com.nashlincoln.blink.ui.SceneListFragment.java
com.nashlincoln.blink.ui.SettingsActivity.java
com.nashlincoln.blink.widget.DeviceSummary.java
com.nashlincoln.blink.widget.SlidingTabLayout.java
com.nashlincoln.blink.widget.SlidingTabStrip.java
com.nashlincoln.dao.Generator.java