Back to project page blink.
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.
package com.nashlincoln.blink.model; /*from w ww. ja v a 2 s. co m*/ import java.util.List; 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; import com.nashlincoln.blink.event.Event; import com.nashlincoln.blink.network.BlinkApi; import com.nashlincoln.blink.nfc.NfcCommand; import java.util.ArrayList; import java.util.HashSet; import java.util.Set; // KEEP INCLUDES END /** * Entity mapped to table SCENE. */ public class Scene { private String name; private Long id; /** Used to resolve relations */ private transient DaoSession daoSession; /** Used for active entity operations. */ private transient SceneDao myDao; private List<SceneDevice> sceneDeviceList; // KEEP FIELDS - put your custom fields here public static final String KEY = "Scene"; private boolean mIsExpanded; // KEEP FIELDS END public Scene() { } public Scene(Long id) { this.id = id; } public Scene(String name, Long id) { this.name = name; this.id = id; } /** called by internal mechanisms, do not call yourself. */ public void __setDaoSession(DaoSession daoSession) { this.daoSession = daoSession; myDao = daoSession != null ? daoSession.getSceneDao() : null; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Long getId() { return id; } public void setId(Long id) { this.id = id; } /** 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<SceneDevice> getSceneDeviceList() { if (sceneDeviceList == null) { if (daoSession == null) { throw new DaoException("Entity is detached from DAO context"); } SceneDeviceDao targetDao = daoSession.getSceneDeviceDao(); List<SceneDevice> sceneDeviceListNew = targetDao._queryScene_SceneDeviceList(id); synchronized (this) { if(sceneDeviceList == null) { sceneDeviceList = sceneDeviceListNew; } } } return sceneDeviceList; } /** Resets a to-many relationship, making the next get call to query for a fresh result. */ public synchronized void resetSceneDeviceList() { sceneDeviceList = 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 deleteWithReferences() { BlinkApp.getDaoSession().runInTx(new Runnable() { @Override public void run() { for (SceneDevice sceneDevice : getSceneDeviceList()) { for (Attribute attribute : sceneDevice.getAttributes()) { attribute.delete(); } sceneDevice.delete(); } delete(); Event.broadcast(Scene.KEY); } }); } public void updateDevices() { BlinkApp.getDaoSession().runInTx(new Runnable() { @Override public void run() { for (SceneDevice sceneDevice : getSceneDeviceList()) { Device device = sceneDevice.getDevice(); device.setOn(sceneDevice.isOn()); device.setLevel(sceneDevice.getLevel()); } } }); } public String toNfc() { List<NfcCommand> commands = new ArrayList<>(); for (SceneDevice sceneDevice : getSceneDeviceList()) { NfcCommand command = new NfcCommand(); Device device = sceneDevice.getDevice(); command.d = device.getId(); command.u = new ArrayList<>(); for (Attribute attribute : sceneDevice.getAttributes()) { NfcCommand.Update update = new NfcCommand.Update(); update.i = attribute.getAttributeTypeId(); update.v = attribute.getValue(); command.u.add(update); } commands.add(command); } return BlinkApi.getGson().toJson(commands); } public void addDevice(long deviceId) { DeviceDao deviceDao = daoSession.getDeviceDao(); Device device = deviceDao.load(deviceId); SceneDevice sceneDevice = SceneDevice.newInstance(); sceneDevice.setDeviceId(device.getId()); sceneDevice.setSceneId(id); daoSession.getSceneDeviceDao().insert(sceneDevice); sceneDevice.copyAttributes(device.getAttributes()); } public void setDeviceIds(long[] deviceIds) { Set<Long> deviceSet = new HashSet<>(); for (long deviceId : deviceIds) { deviceSet.add(deviceId); } for (SceneDevice sceneDevice : getSceneDeviceList()) { if (deviceSet.contains(sceneDevice.getDeviceId())) { deviceSet.remove(sceneDevice.getDeviceId()); } else { sceneDevice.deleteWithReferences(); } } for (Long deviceId : deviceSet) { addDevice(deviceId); } } public boolean isExpanded() { return mIsExpanded; } public void setExpanded(boolean isExpanded) { mIsExpanded = isExpanded; } // KEEP METHODS END }