diff --git a/home-assistant/.gitignore b/home-assistant/.gitignore new file mode 100644 index 0000000..d952bab --- /dev/null +++ b/home-assistant/.gitignore @@ -0,0 +1,24 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar +*.target + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/home-assistant/pom.xml b/home-assistant/pom.xml new file mode 100644 index 0000000..866f6d7 --- /dev/null +++ b/home-assistant/pom.xml @@ -0,0 +1,87 @@ + + + 4.0.0 + + com.totalcross + Home-Assistant + 1.0-SNAPSHOT + Home-Assistant + + + UTF-8 + 5443444B5AAEEB90306B00E4 + + + + + com.totalcross + totalcross-sdk + 7.1.0 + + + + + + totalcross-repo + ip-172-31-40-140-releases + https://maven.totalcross.com/artifactory/repo1 + + + + + + totalcross-repo + ip-172-31-40-140-releases + https://maven.totalcross.com/artifactory/repo1 + + + + + ${project.artifactId} + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.8 + 1.8 + + + + com.totalcross + totalcross-maven-plugin + 2.0.4 + + ${project.name} + + -android +-win32 + + ${totalcross.activation_key} + + + + + + + post-compile + compile + + retrolambda + + + + post-package + package + + package + + + + + + + \ No newline at end of file diff --git a/home-assistant/src/main/java/com/totalcross/HomeAssistant.java b/home-assistant/src/main/java/com/totalcross/HomeAssistant.java new file mode 100644 index 0000000..22979f2 --- /dev/null +++ b/home-assistant/src/main/java/com/totalcross/HomeAssistant.java @@ -0,0 +1,35 @@ +package com.totalcross; + +import totalcross.ui.MainWindow; +import totalcross.sys.Settings; + + +import com.totalcross.util.Colors; +import com.totalcross.containers.MainActivity; +import com.totalcross.containers.SideMenu; +import com.totalcross.database.DatabaseManager; + +public class HomeAssistant extends MainWindow { + + MainActivity mainActivity; + SideMenu sideMenu; + + public HomeAssistant() { + setUIStyle(Settings.MATERIAL_UI); + setBackColor(Colors.BACKGROUD_DEFAULT); + try { + DatabaseManager.getInstance(); + + } catch (Exception e) { + e.printStackTrace(); + } + + } + + @Override + public void initUI() { + sideMenu = new SideMenu(); + add(sideMenu,LEFT, TOP,PARENTSIZE,PARENTSIZE); + } + +} diff --git a/home-assistant/src/main/java/com/totalcross/RunHomeAssistantApplication.java b/home-assistant/src/main/java/com/totalcross/RunHomeAssistantApplication.java new file mode 100644 index 0000000..92ea3e3 --- /dev/null +++ b/home-assistant/src/main/java/com/totalcross/RunHomeAssistantApplication.java @@ -0,0 +1,9 @@ +package com.totalcross; + +import totalcross.TotalCrossApplication; + +public class RunHomeAssistantApplication { + public static void main(String[] args) { + TotalCrossApplication.run(HomeAssistant.class, "/scr", "800x480", "/r", "xxxxxxxxxxxxxxxxxxxxxxxx"); + } +} \ No newline at end of file diff --git a/home-assistant/src/main/java/com/totalcross/containers/ArcSlider.java b/home-assistant/src/main/java/com/totalcross/containers/ArcSlider.java new file mode 100644 index 0000000..3430c45 --- /dev/null +++ b/home-assistant/src/main/java/com/totalcross/containers/ArcSlider.java @@ -0,0 +1,125 @@ +package com.totalcross.containers; + +import com.totalcross.util.Colors; + +import totalcross.ui.Container; +import totalcross.ui.Control; +import totalcross.ui.event.DragEvent; +import totalcross.ui.event.PenEvent; +import totalcross.ui.event.PenListener; +import totalcross.ui.gfx.Coord; +import totalcross.ui.gfx.Graphics; + +public class ArcSlider extends Container { + + int startAngle = 225; + int endAngle = 315; + int radius; + + class Handle extends Control { + + int pos = 0; + Coord center; + + Handle(int pos) { + this.pos = pos; + center = getAnglePoint(pos); + this.addPenListener(new PenListener() { + boolean isDragging = false; + + @Override + public void penDown(PenEvent arg0) { + // System.out.println(arg0); + } + + @Override + public void penDrag(DragEvent arg0) { + // if (isInside(arg0.x, arg0.y, 10)) + if (isDragging) { + // System.out.println(arg0); + int angle = findAngle(arg0.x, arg0.y); + if (angle != Handle.this.pos) { + Handle.this.pos = angle; + center = getCoordByAngle(Handle.this.pos); + repaint(); + } + } + } + + @Override + public void penDragEnd(DragEvent arg0) { + // System.out.println(arg0); + isDragging = false; + } + + @Override + public void penDragStart(DragEvent arg0) { + if (isInside(arg0.x, arg0.y, 10)) { + // System.out.println(arg0); + isDragging = true; + } + } + + @Override + public void penUp(PenEvent arg0) { + // System.out.println(arg0); + } + }); + } + + @Override + public void onPaint(Graphics g) { + g.drawCircle(center.x, center.y, 10); + } + + public boolean isInside(int x, int y, int radius) { + int dx = Math.abs(x - center.x); + int dy = Math.abs(y - center.y); + + if (dx > radius) + return false; + if (dy > radius) + return false; + + if (dx + dy <= radius) + return true; + return (dx * dx + dy * dy <= radius * radius); + } + } + + @Override + public void initUI() { + super.initUI(); + this.radius = Math.min(width, height) / 3; + add(new Handle(startAngle), 0, 0, width, height); + add(new Handle(startAngle), 0, 0, width, height); + } + + @Override + public void onPaint(Graphics g) { + super.onPaint(g); + g.backColor = Colors.BACKGROUD_DEFAULT; + g.fillRect(0, 0, width, height); + g.drawArc(width / 2, height / 2, radius, 315, 225); + } + + // Faz o mesmo que getAnglePoint, mas não consegui escolher entre as duas + private Coord getCoordByAngle(int angle) { + Coord result = new Coord(); + result.x = (width / 2) + (int) (Math.cos(Math.toRadians(angle)) * radius); + result.y = (height / 2) - (int) (Math.sin(Math.toRadians(angle)) * radius); + return result; + } + + private Coord getAnglePoint(int angle) { + Coord out = new Coord(); + this.getGraphics().getAnglePoint(width / 2, height / 2, radius, radius, angle, out); + return out; + } + + private int findAngle(int x, int y) { + double theta = Math.toDegrees(Math.atan2((height / 2) - y, x - (width / 2))); + theta = (theta + 360) % 360; + return (int) theta; + } +} \ No newline at end of file diff --git a/home-assistant/src/main/java/com/totalcross/containers/CircleContainer.java b/home-assistant/src/main/java/com/totalcross/containers/CircleContainer.java new file mode 100644 index 0000000..b2c7376 --- /dev/null +++ b/home-assistant/src/main/java/com/totalcross/containers/CircleContainer.java @@ -0,0 +1,18 @@ +package com.totalcross.containers; + +import totalcross.ui.Control; +import totalcross.ui.gfx.Graphics; + +public class CircleContainer extends Control { + public CircleContainer(int cor){ + this.cor = cor; + } + int cor; + @Override + public void onPaint(Graphics g) { + g.foreColor = cor; + g.drawCircle(width /2, height/2, 30); + + } + +} diff --git a/home-assistant/src/main/java/com/totalcross/containers/Demo.java b/home-assistant/src/main/java/com/totalcross/containers/Demo.java new file mode 100644 index 0000000..1bdcf52 --- /dev/null +++ b/home-assistant/src/main/java/com/totalcross/containers/Demo.java @@ -0,0 +1,417 @@ +package com.totalcross.containers; + +import com.totalcross.util.Colors; +import com.totalcross.util.Fonts; +import totalcross.sys.Vm; +import totalcross.ui.Button; +import totalcross.ui.ComboBox; +import totalcross.ui.Container; +import totalcross.ui.Label; +import totalcross.ui.Radio; +import totalcross.ui.ScrollContainer; +import totalcross.ui.Switch; +import totalcross.ui.dialog.ColorChooserBox; +import totalcross.ui.font.Font; +import totalcross.ui.gfx.Color; + +public class Demo extends ScrollContainer{ + + public Container First; + public Container Second; + public Container Third; + public Container Fourth; + + public Label lblTitle; + public Label lblSubTitle; + public Label lblIdioma; + public Label lblNumericFormatting; + public Label lblNumericFormattingSub; + public Label lblHourFormat; + public Label lblHourFormatSub; + public Label lblTheme; + public Label lblControlPanel; + public Label lblControlPanelSub; + public Label lbl01; + public Label lbl01Sub; + public Label lblOcult; + public Label lblOcultSub; + public Label lblOcultSub2; + public Label lblVibrar; + public Label lblVibrarSub; + public Label lblNotify; + public Label lblNotifySub; + public Label lblMode; + public Label lblModeSub; + public Label lblClose; + public Label lblCloseSub; + public Label lblShortcuts; + public Label lblShortcutsSub; + public Label lblTitleModulo; + public Label lblTitleTokens; + public Label lblTokensSub; + public Label lblTitleTokensAccess; + public Label lblTokensAccessSub; + public Label lblTokensAccessStatus; + + public Button Edit; + public Button CreateToken; + public Button Exit; + + public ComboBox cbnIdioma; + public ComboBox cbnNumericFormatting; + public ComboBox cbnHourFormat; + public ComboBox cbnTheme; + public ComboBox cbnControlPane; + + public Switch sldOcult; + public Switch sldVibrar; + public Switch sldNotify; + public Switch sldMode; + public Switch sldClose; + public Switch sldShorcuts; + + public ColorChooserBox colorMain; + + public Radio auto; + public Radio Claro; + public Radio Escuro; + + @Override + public void initUI() { + + try { + setScrollBars(false, true); + setBackForeColors(0xF7F7F7, 0x000000); + + First = new Container(); + Second = new Container(); + Third = new Container(); + Fourth = new Container(); + + lblTitle = new Label("Demo User"); + lblSubTitle = new Label("Você está logado como Demo User. Você é um proprietário."); + lblIdioma = new Label("Idioma"); + lblNumericFormatting = new Label("Formatação numérica"); + lblNumericFormattingSub = new Label("Choose how numbers are formatted."); + lblHourFormat = new Label("Formato de hora"); + lblHourFormatSub = new Label("Escolha como os horários são formatados."); + lblTheme = new Label("Tema"); + lblControlPanel = new Label("Painel de controle"); + lblControlPanelSub = new Label("Escolha um painel padrão para este dispositivo."); + lbl01 = new Label("Altere a ordem e oculte os itens da barra lateral"); + lbl01Sub = new Label("Pode também pressionar e segurar o cabeçalho da " + + "barra lateral \n para ativar o modo de edição."); + lblOcult = new Label("Sempre ocultar a barra lateral"); + lblOcultSub = new Label("Isto irá ocultar a barra lateral por padrão, semelhante à \n experiência móvel."); + lblVibrar = new Label("Vibrar"); + lblVibrarSub = new Label("Ative ou desative a vibração neste dispositivo ao controlar \n dispositivos."); + lblNotify = new Label("Notificações push"); + lblNotifySub = new Label("Envie notificações para este dispositivo"); + lblMode = new Label("Modo Avançado"); + lblModeSub = new Label("Desbloqueia recursos avançados."); + lblClose = new Label("Fechar a conexão automaticamente"); + lblCloseSub = new Label("Devemos fechar a conexão com o servidor depois de ficar oculto por \n 5 minutos?"); + lblShortcuts = new Label("Atalhos de Teclado"); + lblShortcutsSub = new Label("Ativar ou desativar atalhos de teclado para executar várias ações na \n IU."); + lblTitleModulo = new Label("Módulos de Autenticação Multifator"); + lblTitleTokens = new Label("Tokens de atualização"); + lblTokensSub = new Label("Cada token de atualização representa uma sessão de login. Os tokens de atualização serão \n" +"removidos automaticamente quando você clicar em efetuar logout. Os tokens de \n" + + "atualização a seguir estão ativos na sua conta no momento."); + lblTitleTokensAccess = new Label("Tokens de acesso de longa duração"); + lblTokensAccessSub = new Label("Crie tokens de acesso de longa duração para permitir que seus scripts interajam com \n sua instância do Home Assistant. Cada token será válido por 10 anos a partir da criação. Os \n" + + "seguintes tokens de acesso de longa duração estão atualmente ativos"); + lblTokensAccessStatus = new Label("Você ainda não tem tokens de acesso de longa duração."); + + Edit = new Button("EDITAR"); + CreateToken = new Button("CRIAR TOKEN"); + Exit = new Button("SAIR"); + + + sldOcult = new Switch(); + sldVibrar = new Switch(); + sldNotify = new Switch(); + sldMode = new Switch(); + sldClose = new Switch(); + sldShorcuts = new Switch(); + + auto = new Radio("Automático"); + Claro = new Radio("Claro"); + Escuro = new Radio("Escuro"); + + //Configurando Labels + lblTitle.transparentBackground = true; + lblSubTitle.transparentBackground = true; + lblIdioma.transparentBackground = true; + lblNumericFormatting.transparentBackground = true; + lblNumericFormattingSub.transparentBackground = true; + lblHourFormat.transparentBackground = true; + lblHourFormatSub.transparentBackground = true; + lblTheme.transparentBackground = true; + lblControlPanel.transparentBackground = true; + lblControlPanelSub.transparentBackground = true; + lbl01.transparentBackground = true; + lbl01Sub.transparentBackground = true; + lblOcult.transparentBackground = true; + lblOcultSub.transparentBackground = true; + lblVibrar.transparentBackground = true; + lblVibrarSub.transparentBackground = true; + lblNotify.transparentBackground = true; + lblNotifySub.transparentBackground = true; + lblMode.transparentBackground = true; + lblModeSub.transparentBackground = true; + lblClose.transparentBackground = true; + lblCloseSub.transparentBackground = true; + lblShortcuts.transparentBackground = true; + lblShortcutsSub.transparentBackground = true; + lblTitleModulo.transparentBackground = true; + lblTitleTokens.transparentBackground = true; + lblTokensSub.transparentBackground = true; + lblTitleTokensAccess.transparentBackground = true; + lblTokensAccessSub.transparentBackground = true; + lblTokensAccessStatus.transparentBackground = true; + + lblTitle.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 40)); + lblSubTitle.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 15)); + lblIdioma.setFont(Font.getFont(Fonts.FONT_DEFAULT, true, 15)); + lblNumericFormatting.setFont(Font.getFont(Fonts.FONT_DEFAULT, true, 15)); + lblNumericFormattingSub.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 15)); + lblHourFormat.setFont(Font.getFont(Fonts.FONT_DEFAULT, true, 15)); + lblHourFormatSub.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 15)); + lblTheme.setFont(Font.getFont(Fonts.FONT_DEFAULT, true, 15)); + lblControlPanel.setFont(Font.getFont(Fonts.FONT_DEFAULT, true, 15)); + lblControlPanelSub.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 15)); + lbl01.setFont(Font.getFont(Fonts.FONT_DEFAULT, true, 15)); + lbl01Sub.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 15)); + lblOcult.setFont(Font.getFont(Fonts.FONT_DEFAULT, true, 15)); + lblOcultSub.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 15)); + lblVibrar.setFont(Font.getFont(Fonts.FONT_DEFAULT, true, 15)); + lblVibrarSub.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 15)); + lblNotify.setFont(Font.getFont(Fonts.FONT_DEFAULT, true, 15)); + lblNotifySub.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 15)); + lblMode.setFont(Font.getFont(Fonts.FONT_DEFAULT, true, 15)); + lblModeSub.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 15)); + lblClose.setFont(Font.getFont(Fonts.FONT_DEFAULT, true, 15)); + lblCloseSub.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 15)); + lblShortcuts.setFont(Font.getFont(Fonts.FONT_DEFAULT, true, 15)); + lblShortcutsSub.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 15)); + lblTitleModulo.setFont(Font.getFont(Fonts.FONT_DEFAULT, true, 15)); + lblTitleTokens.setFont(Font.getFont(Fonts.FONT_DEFAULT, true, 15)); + lblTokensSub.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 15)); + lblTitleTokensAccess.setFont(Font.getFont(Fonts.FONT_DEFAULT, true, 15)); + lblTokensAccessSub.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 15)); + lblTokensAccessStatus.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 15)); + + + //Configurando Radio Button + auto.transparentBackground = true; + Claro.transparentBackground = true; + Escuro.transparentBackground = true; + + //Adicioanndo itens no array + String[] itemsIdioma = { + "Afrikaans" + ,"عربية" + ,"Български" + ,"বাংলা" + ,"Bosanski" + ,"Català" + ,"Čeština" + ,"Cymraeg" + ,"Dansk" + ,"Deutsch" + ,"Ελληνικά" + ,"English" + ,"English (GB)" + ,"Esperanto" + ,"Español" + ,"Español (Latin America)" + ,"Eesti" + ,"Euskara" + ,"فارسی" + ,"Suomi" + ,"Frysk" + ,"Français" + ,"Galego" + ,"Schwiizerdütsch" + ,"עברית" + ,"हिन्दी" + ,"Hrvatski" + ,"Magyar" + ,"Հայերեն" + ,"Indonesia" + ,"Italiano" + ,"Íslenska" + ,"日本語" + ,"Kartuli" + ,"한국어" + ,"Lëtzebuergesch" + ,"Lietuvių" + ,"Latviešu" + ,"Nederlands" + ,"Norsk Bokmål" + ,"Norsk Nynorsk" + ,"Polski" + ,"Português" + ,"Português (BR)" + ,"Română" + ,"Русский" + ,"Slovenčina" + ,"Slovenščina" + ,"Српски" + ,"Srpski" + ,"Svenska" + ,"தமிழ்" + ,"తెలుగు" + ,"ภาษาไทย" + ,"Türkçe" + ,"Українська" + ,"اُردُو" + ,"Tiếng Việt" + ,"简体中文" + ,"繁體中文" + ,"Test"}; + + String[] itemsNumericFormatting = { + "Auto (use language setting)" + ,"1.234.567,89" + ,"Use system locale" + ,"1.234.567,89" + ,"1,234,567.89" + ,"1.234.567,89" + ,"1 234 567,89" + ,"None" + ,"1234567.89" + }; + + String[] itemsHourFormat = { + "Automático (usar configuração de idioma)" + ,"13:30" + ,"Use a localidade do sistema" + ,"13:30" + ,"12 horas (AM/PM)" + ,"1:30 PM" + ,"24 horas" + ,"13:30" + }; + + String[] itemsTheme = { + "Backend-selected" + ,"default" + ,"mock'" + }; + + //Criando combo box + cbnIdioma = new ComboBox(itemsIdioma); + cbnNumericFormatting = new ComboBox(itemsNumericFormatting); + cbnHourFormat = new ComboBox(itemsHourFormat); + cbnTheme = new ComboBox(itemsTheme); + cbnControlPane = new ComboBox(); + + //Configurando combo box + cbnIdioma.caption = itemsIdioma[0]; + cbnNumericFormatting.caption = itemsNumericFormatting[0]; + cbnHourFormat.caption = itemsHourFormat[0]; + cbnTheme.caption = itemsTheme[0]; + cbnControlPane.caption = "defautl"; + cbnControlPane.enableSearch = false; + + //Adicionando os containers ao layout + add(First,LEFT,TOP); + add(Second,LEFT,TOP + 800); + add(Third,LEFT,TOP + 850); + add(Fourth,LEFT,TOP + 900); + + //Adicionando componentes aos containers + First.add(lblTitle,LEFT + 10,TOP); + First.add(lblSubTitle,SAME ,AFTER + 2 ); + First.add(lblIdioma,SAME ,AFTER + 5); + First.add(lblNumericFormatting,SAME ,AFTER + 12); + First.add(lblNumericFormattingSub,SAME ,AFTER + 2); + First.add(lblHourFormat,SAME ,AFTER + 12); + First.add(lblHourFormatSub,SAME ,AFTER + 2); + First.add(lblTheme,SAME ,AFTER + 12); + First.add(auto,SAME + 5 ,AFTER + 12); + First.add(Claro,SAME + 120 ,SAME); + First.add(Escuro,SAME + 80 ,SAME); + First.add(lblControlPanel,LEFT + 10 ,AFTER + 12); + First.add(lblControlPanelSub,SAME ,AFTER + 2); + First.add(lbl01,SAME ,AFTER + 12); + First.add(lbl01Sub,SAME ,AFTER + 2); + First.add(lblOcult,SAME ,AFTER + 12); + First.add(lblOcultSub,SAME ,AFTER + 2); + First.add(lblVibrar,SAME ,AFTER + 12); + First.add(lblVibrarSub,SAME ,AFTER + 2); + First.add(lblNotify,SAME ,AFTER + 12); + First.add(lblNotifySub,SAME ,AFTER + 2); + First.add(lblMode,SAME ,AFTER + 12); + First.add(lblModeSub,SAME ,AFTER + 2); + First.add(lblClose,SAME ,AFTER + 12); + First.add(lblCloseSub,SAME ,AFTER + 2); + First.add(lblShortcuts,SAME ,AFTER + 12); + First.add(lblShortcutsSub,SAME ,AFTER + 2); + + First.add(cbnIdioma, LEFT + 330 , TOP + 63,150,40); + First.add(cbnNumericFormatting, SAME , AFTER + 4,150,40); + First.add(cbnHourFormat, SAME , AFTER + 4,150,40); + First.add(cbnTheme, SAME , AFTER + 4,150,40); + First.add(cbnControlPane, SAME , AFTER + 40,150,40); + + First.add(Edit, SAME + 55, AFTER + 15); + + First.add(sldOcult,SAME + 35,AFTER + 40); + First.add(sldVibrar,SAME ,AFTER + 50); + First.add(sldNotify,SAME ,SAME + 55); + First.add(sldMode,SAME ,AFTER + 35); + First.add(sldClose,SAME ,AFTER + 40); + First.add(sldShorcuts,SAME ,AFTER + 45); + + First.add(Exit,LEFT + 10, AFTER + 20); + + Second.add(lblTitleModulo,LEFT + 10, TOP + 20); + + Third.add(lblTitleTokens, LEFT + 10, TOP + 20); + Third.add(lblTitleTokens, LEFT + 10, TOP + 20); + + Fourth.add(lblTitleTokensAccess, LEFT + 10, AFTER + 20); + Fourth.add(lblTokensAccessSub, LEFT + 10, AFTER + 20); + Fourth.add(lblTokensAccessStatus, LEFT + 10, AFTER + 20); + Fourth.add(CreateToken, LEFT + 10, AFTER + 20); + + // Configurando o container + First.setBackColor(Colors.BACKGROUD_DEFAULT); + First.setBorderRadius(5); + First.setBorderStyle(BORDER_RAISED); + First.setBackColor(Color.WHITE); + + Second.setBackColor(Colors.BACKGROUD_DEFAULT); + Second.setBorderRadius(5); + Second.setBorderStyle(BORDER_RAISED); + Second.setBackColor(Color.WHITE); + + Third.setBackColor(Colors.BACKGROUD_DEFAULT); + Third.setBorderRadius(5); + Third.setBorderStyle(BORDER_RAISED); + Third.setBackColor(Color.WHITE); + + Fourth.setBackColor(Colors.BACKGROUD_DEFAULT); + Fourth.setBorderRadius(5); + Fourth.setBorderStyle(BORDER_RAISED); + Fourth.setBackColor(Color.WHITE); + + // Configurando tamanho do container + First.setRect(LEFT,TOP, 500, 800); + Second.setRect(LEFT,TOP + 800, KEEP, KEEP); + Third.setRect(LEFT,TOP + 850, KEEP, KEEP); + Fourth.setRect(LEFT,TOP + 900, KEEP, KEEP); + + First.resize(); + Second.resize(); + Third.resize(); + Fourth.resize(); + + } catch (Exception e) { + Vm.debug(e.toString()); + //e.printStackTrace(); + } + } +} diff --git a/home-assistant/src/main/java/com/totalcross/containers/DoorBell.java b/home-assistant/src/main/java/com/totalcross/containers/DoorBell.java new file mode 100644 index 0000000..90b9fd9 --- /dev/null +++ b/home-assistant/src/main/java/com/totalcross/containers/DoorBell.java @@ -0,0 +1,81 @@ +package com.totalcross.containers; + +import com.totalcross.util.Colors; +import com.totalcross.util.Fonts; + +import totalcross.ui.Container; +import totalcross.ui.Label; +import totalcross.ui.font.Font; +import totalcross.ui.gfx.Color; +import totalcross.ui.icon.Icon; +import totalcross.ui.icon.MaterialIcons; + +public class DoorBell extends Container { + + public DoorBell() { + + } + + // declarações + public Label title, fDoor, fDMontion, fDLDing, fDLMotion, fDEstado, fDMEstado, fDLDtempo, fDLMtempo; + public Icon fDoorIcon, fDMIcon, fDLDIcon, fDLMoIcon; + + public void initUI() { + + // setando labels + title = new Label("Doorbell"); + fDoor = new Label("Front Door Ding"); + fDMontion = new Label("Front Door Motion"); + fDLDing = new Label("Front Door Last Ding"); + fDLMotion = new Label("Front Door Last Motion"); + fDEstado = new Label("Desocupado"); + fDMEstado = new Label("Desligado"); + fDLDtempo = new Label("06:44"); + fDLMtempo = new Label("13:21"); + + // setando icones + fDoorIcon = new Icon(MaterialIcons._HOME); + fDMIcon = new Icon(MaterialIcons._DIRECTIONS_WALK); + fDLDIcon = new Icon(MaterialIcons._HISTORY); + fDLMoIcon = new Icon(MaterialIcons._HISTORY); + + // configurando container + setBackColor(Colors.BACKGROUD_DEFAULT); + setBorderRadius(5); + setBorderStyle(BORDER_RAISED); + setBackColor(Color.WHITE); + + // configurando icones + fDoorIcon.setForeColor(Colors.FROZEN_DEFAULT); + fDMIcon.setForeColor(Colors.FROZEN_DEFAULT); + fDLDIcon.setForeColor(Colors.FROZEN_DEFAULT); + fDLMoIcon.setForeColor(Colors.FROZEN_DEFAULT); + + // configurando labels + title.setFont(Font.getFont(Fonts.FONT_DEFAULT, true, title.getFont().size + 10)); + fDoor.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 15)); + fDMontion.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 15)); + fDEstado.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 15)); + fDMEstado.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 15)); + fDLDing.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 15)); + fDLDtempo.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 15)); + fDLMotion.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 15)); + fDLMtempo.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 15)); + + add(title, LEFT + 10, TOP); + add(fDoorIcon, LEFT + 10, AFTER + 30); + add(fDoor, AFTER + 10, SAME + 5); + add(fDEstado, RIGHT_OF + 100, SAME); + add(fDMIcon, LEFT + 12, AFTER + 10); + add(fDMontion, AFTER + 10, SAME + 5); + add(fDMEstado, RIGHT_OF + 90, SAME); + add(fDLDIcon, LEFT + 8, AFTER + 10); + add(fDLDing, AFTER + 10, SAME); + add(fDLDtempo, RIGHT_OF + 75, SAME); + add(fDLMoIcon, LEFT + 8, AFTER + 10); + add(fDLMotion, AFTER + 10, SAME); + add(fDLMtempo, RIGHT_OF + 65, SAME); + + this.resize(); + } +} diff --git a/home-assistant/src/main/java/com/totalcross/containers/Energy.java b/home-assistant/src/main/java/com/totalcross/containers/Energy.java new file mode 100644 index 0000000..1e11c72 --- /dev/null +++ b/home-assistant/src/main/java/com/totalcross/containers/Energy.java @@ -0,0 +1,136 @@ +package com.totalcross.containers; + +import com.totalcross.util.Colors; +import com.totalcross.util.Images; + +import totalcross.io.IOException; +import totalcross.ui.Button; +import totalcross.ui.Container; +import totalcross.ui.ScrollBar; +import totalcross.ui.Slider; +import totalcross.ui.font.Font; +import totalcross.ui.gfx.Color; +import totalcross.ui.image.Image; +import totalcross.ui.image.ImageException; +import totalcross.util.UnitsConverter; + +public class Energy extends Container { + public Energy() { + + } + + public Container energyContainer; + public Button btnDashboard; + //public ImageControl eletrica, home; + //public CircleContainer eletrica, home; + //public Label lblNFossil, lblSolar, lblGrid1, lblGrid2, lblHome; + public Slider sldNFossil, sldSolGrid, sldSolHome, sldGridHome; + public Generator nFossil, solar, eletrica, home; + public Image imgNFossil, imgSolar, imgEletrica, imgHome; + static final int SIZEC = 100; + + public void initUI() { + + energyContainer = new Container(); + + Images.loadNonFossil(); + Images.loadSolarPower(); + Images.loadEletricity(); + Images.loadHomeEnergy(); + + + + + add(energyContainer, LEFT, TOP, 200, 200); + energyContainer.setBorderStyle(BORDER_RAISED); + energyContainer.setBackColor(Colors.BACKGROUD_DEFAULT); + + try { + imgNFossil = new Image("images/imgNFossil.png"); + imgSolar = new Image("images/Solar.png"); + imgEletrica = new Image("images/Grid.png"); + imgHome = new Image("images/Home.png"); + + } catch (IOException | ImageException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + sldNFossil = new Slider(ScrollBar.VERTICAL); + sldNFossil.setFont(Font.getFont(false, Font.NORMAL_SIZE)); + sldNFossil.appId = 1; + sldNFossil.setLiveScrolling(false); + sldNFossil.setBackColor(0x00C301); + sldNFossil.sliderColor = 0x00C301; + sldNFossil.setPressColor(0x00C301); + sldNFossil.setMaximum(15); + sldNFossil.markerSize = 0; + sldNFossil.barHeight = 2; + + sldSolGrid = new Slider(ScrollBar.VERTICAL); + sldSolGrid.setFont(Font.getFont(false, Font.NORMAL_SIZE)); + sldSolGrid.appId = 2; + sldSolGrid.setLiveScrolling(true); + sldSolGrid.setBackColor(0xff781f); + sldSolGrid.sliderColor = 0xff781f; + sldSolGrid.setPressColor(0xff781f); + sldSolGrid.setMaximum(50); + sldSolGrid.markerSize = 2; + sldSolGrid.barHeight = 2; + + sldSolHome = new Slider(ScrollBar.VERTICAL); + sldSolHome.setFont(Font.getFont(false, Font.NORMAL_SIZE)); + sldSolHome.appId = 3; + sldSolHome.setLiveScrolling(true); + sldSolHome.setBackColor(0xff781f); + sldSolHome.sliderColor = 0xff781f; + sldSolHome.setPressColor(0xff781f); + sldSolHome.setMaximum(50); + sldSolHome.markerSize = 2; + sldSolHome.barHeight = 2; + + sldGridHome = new Slider(ScrollBar.HORIZONTAL); + sldGridHome.setFont(Font.getFont(false, Font.NORMAL_SIZE)); + sldGridHome.appId = 4; + sldGridHome.setLiveScrolling(true); + sldGridHome.setBackColor(0x2b5bb0); + sldGridHome.sliderColor = 0x2b5bb0; + sldGridHome.setPressColor(0x2b5bb0); + sldGridHome.setMaximum(55); + sldGridHome.markerSize = 2; + sldGridHome.barHeight = 2; + + + nFossil = new Generator(Color.GREEN, 2.1, imgNFossil); + solar = new Generator(Color.YELLOW, 5.2,imgSolar); + eletrica = new Generator(Color.BLUE,3.6, imgEletrica); + home = new Generator(Color.RED, 9, imgHome); + + + nFossil.setConsumer(eletrica, 2.1); + eletrica.setConsumer(home, 3.6); + solar.setConsumer(home, 4.9); + solar.setConsumer(eletrica, 1.4); + + + solar.transparentBackground = true; + eletrica.transparentBackground = true; + home.transparentBackground = true; + + + + btnDashboard = new Button("GO TO ENERGY DASHBOARD", Button.BORDER_NONE); + + btnDashboard.setForeColor(Colors.FROZEN_DEFAULT); + + energyContainer.add(nFossil, LEFT, TOP, 80, 80); + energyContainer.add(solar, RIGHT, TOP, 80, 80); + energyContainer.add(eletrica, LEFT, TOP + 110, 80, 80); + energyContainer.add(home, RIGHT + 80, TOP + 110, 80, 80); + energyContainer.add(btnDashboard, CENTER, BOTTOM + 100, PARENTSIZE, PREFERRED); + + energyContainer.resize(); + + } + +} diff --git a/home-assistant/src/main/java/com/totalcross/containers/EnergyMenu.java b/home-assistant/src/main/java/com/totalcross/containers/EnergyMenu.java new file mode 100644 index 0000000..a620836 --- /dev/null +++ b/home-assistant/src/main/java/com/totalcross/containers/EnergyMenu.java @@ -0,0 +1,10 @@ +package com.totalcross.containers; + +import totalcross.ui.ScrollContainer; + +public class EnergyMenu extends ScrollContainer{ + + +} + + diff --git a/home-assistant/src/main/java/com/totalcross/containers/Entertainment.java b/home-assistant/src/main/java/com/totalcross/containers/Entertainment.java new file mode 100644 index 0000000..7b307ac --- /dev/null +++ b/home-assistant/src/main/java/com/totalcross/containers/Entertainment.java @@ -0,0 +1,142 @@ +package com.totalcross.containers; + +import com.totalcross.util.Colors; +import com.totalcross.util.Images; + +import totalcross.ui.Button; +import totalcross.ui.ComboBox; +import totalcross.ui.Container; +import totalcross.ui.ImageControl; +import totalcross.ui.Label; +import totalcross.ui.ScrollBar; +import totalcross.ui.Slider; +import totalcross.ui.font.Font; +import totalcross.ui.gfx.Color; +import totalcross.ui.icon.Icon; +import totalcross.ui.icon.MaterialIcons; + +public class Entertainment extends Container { + static final int SIZEC = 100; + // public Container entretenimento; + + public Entertainment() { + + } + + public Label title, atividade, comutadorHDMI, entradaHDMI, volume, tempTV, desligarTV, txtDevice, txtAtiv, + txtTempTV; + public String[] services = { "PowerOFF", "Watch Fire TV", "YouTube", "SATV", "Watch Apple TV" }; + public String[] comutHDMI = { "AppleTV", "FireTV", "Shield" }; + public String[] entHDMI = { "imputHDMI1", "imputHDMI2", "imputHDMI3", "imputHDMI4" }; + public Slider vol; + public Button desl; + public ComboBox actiBox, comutBox, enterBox; + public Icon ativIcon, comutIcon, entIcon, volIcon, temptvIcon, desligarIcon; + public ImageControl imgHarmony; + + public void initUI() { + + title = new Label("Entretenimento"); + atividade = new Label("Atividade"); + comutadorHDMI = new Label("Comutador HDMI"); + entradaHDMI = new Label("Entrada HDMI"); + volume = new Label("Volume"); + tempTV = new Label("Tempo total de TV"); + desligarTV = new Label("Desligar televisão"); + txtDevice = new Label("Harmony"); + txtAtiv = new Label("YouTube "); + txtTempTV = new Label("0,42 h "); + + title.setFont(Font.getFont("Times New Roman", true, title.getFont().size + 10)); + txtDevice.setFont(Font.getFont("Times New Roman", false, atividade.getFont().size + 2)); + txtAtiv.setFont(Font.getFont("Times New Roman", false, txtAtiv.getFont().size + 2)); + volume.setFont(Font.getFont("Times New Roman", false, txtAtiv.getFont().size - 1)); + tempTV.setFont(Font.getFont("Times New Roman", false, txtAtiv.getFont().size - 1)); + txtTempTV.setFont(Font.getFont("Times New Roman", false, txtAtiv.getFont().size - 1)); + desligarTV.setFont(Font.getFont("Times New Roman", false, txtAtiv.getFont().size - 1)); + + atividade.setForeColor(0x808080); + comutadorHDMI.setForeColor(0x808080); + entradaHDMI.setForeColor(0x808080); + + actiBox = new ComboBox(services); + comutBox = new ComboBox(comutHDMI); + enterBox = new ComboBox(entHDMI); + + actiBox.borderColor = 0x000000; + actiBox.setBorderStyle(BORDER_LOWERED); + comutBox.borderColor = 0x000000; + comutBox.setBorderStyle(BORDER_LOWERED); + + vol = new Slider(ScrollBar.HORIZONTAL); + vol.setFont(Font.getFont(false, Font.NORMAL_SIZE)); + vol.appId = 1; + vol.setLiveScrolling(true); + vol.setBackColor(Colors.BACKGROUD_DEFAULT); + vol.sliderColor = 0xADD8E6; + vol.ticksColor = 0xFFFAFA; + vol.circleColor = 0xADD8E6; + vol.setPressColor(0xADD8E6); + vol.invertDirection = true; + vol.barHeight = 5; + vol.setMaximum(100); + vol.setMinimum(1); + vol.setValue(20); + vol.markerSize = 5; + + ativIcon = new Icon(MaterialIcons._SETTINGS_REMOTE); + comutIcon = new Icon(MaterialIcons._SETTINGS_REMOTE); + entIcon = new Icon(MaterialIcons._SETTINGS_REMOTE); + volIcon = new Icon(MaterialIcons._VOLUME_UP); + temptvIcon = new Icon(MaterialIcons._TRENDING_UP); + desligarIcon = new Icon(MaterialIcons._POWER); + + ativIcon.setForeColor(0x007FFF); + comutIcon.setForeColor(0x007FFF); + entIcon.setForeColor(0x007FFF); + volIcon.setForeColor(0x007FFF); + temptvIcon.setForeColor(0x007FFF); + desligarIcon.setForeColor(0x007FFF); + + desl = new Button("Executar"); + desl.setForeColor(0x007FFF); + desl.transparentBackground = true; + desl.setBorder(BORDER_NONE); + desl.setFont(Font.getFont("Times New Roman", true, txtAtiv.getFont().size + 1)); + + setBackColor(Colors.BACKGROUD_DEFAULT); + setBorderRadius(5); + setBorderStyle(BORDER_RAISED); + setBackColor(Color.WHITE); + + Images.loadHarmony(); + + imgHarmony = new ImageControl(Images.imgHarmony); + + imgHarmony.transparentBackground = true; + + add(title, LEFT + 10, TOP); + add(imgHarmony, LEFT + 10, TOP + 50); + add(txtDevice, LEFT + 80, TOP + 65); + add(txtAtiv, RIGHT + 250, TOP + 65); + add(ativIcon, LEFT + 25, AFTER + 80); + add(atividade, AFTER + 5, SAME - 15); + add(actiBox, SAME, SAME + 15, 200, 30); + add(comutIcon, LEFT + 25, AFTER + 20); + add(comutadorHDMI, AFTER + 5, SAME - 15); + add(comutBox, SAME, SAME + 15, 200, 30); + add(entIcon, LEFT + 25, AFTER + 20); + add(entradaHDMI, AFTER + 5, SAME - 15); + add(enterBox, SAME, SAME + 15, 200, 30); + add(volIcon, LEFT + 25, AFTER + 20); + add(volume, AFTER + 5, SAME); + add(vol, RIGHT + 250, SAME, 70, PREFERRED); + add(temptvIcon, LEFT + 25, AFTER + 20); + add(tempTV, AFTER + 5, SAME); + add(txtTempTV, RIGHT + 250, SAME); + add(desligarIcon, LEFT + 25, AFTER + 20); + add(desligarTV, AFTER + 5, SAME + 1); + add(desl, RIGHT + 250, SAME - 5); + + } +} diff --git a/home-assistant/src/main/java/com/totalcross/containers/Generator.java b/home-assistant/src/main/java/com/totalcross/containers/Generator.java new file mode 100644 index 0000000..a3795e1 --- /dev/null +++ b/home-assistant/src/main/java/com/totalcross/containers/Generator.java @@ -0,0 +1,34 @@ +package com.totalcross.containers; + +import totalcross.ui.gfx.Color; +import totalcross.ui.gfx.Graphics; +import totalcross.ui.image.Image; + +public class Generator extends CircleContainer { + + public Generator(int cor, double kwh, Image img) { + super(cor); + this.kwh = kwh; + this.img = img; + //TODO Auto-generated constructor stub + } + double kwh, value; + Image img; + CircleContainer consumer; + + @Override + public void onPaint(Graphics g) { + super.onPaint(g); + g.foreColor = Color.BLACK; + g.drawImage(img, width/3, height/4, false); + g.drawText(Double.toString(kwh) + " KwH", width/4, height/2, 0); + if(consumer!= null){ + g.drawLine(width/2, height/2, (consumer.getX() + consumer.getWidth())/2, (consumer.getY() + consumer.getHeight())/2); + } + } + + public void setConsumer(CircleContainer consumer, double value){ + this.consumer = consumer; + this.value = value; + } +} diff --git a/home-assistant/src/main/java/com/totalcross/containers/Graphifc.java b/home-assistant/src/main/java/com/totalcross/containers/Graphifc.java new file mode 100644 index 0000000..686d436 --- /dev/null +++ b/home-assistant/src/main/java/com/totalcross/containers/Graphifc.java @@ -0,0 +1,195 @@ +package com.totalcross.containers; +import java.util.ArrayList; +import java.util.List; + +import totalcross.sys.Convert; +import totalcross.ui.Control; +import totalcross.ui.gfx.Color; +import totalcross.ui.gfx.Graphics; +import totalcross.ui.gfx.Rect; +public class Graphifc , Y extends Number> extends Control { + + Series[] series; + int yMin = 0; + int yMax; + int yStep = 1000 * 1000; + int yMaxValue; + + final int borderGap = 10; + final int xTextHeight = 52; + final int yGap = 20; + int yTextLen; + int yCount;; + + Rect r; + int widthX; + + private List listToDraw = new ArrayList<>(); + + @SafeVarargs + public Graphifc(Series... series) { + reset(); + listToDraw.add(0); + changeSeries(series); + } + + public void reset() { + listToDraw.clear(); + } + + @Override + protected void onBoundsChanged(boolean screenChanged) { + r = new Rect(borderGap, borderGap, width - (borderGap * 2), height - (borderGap * 2)); + widthX = r.width - 1 - yTextLen - yGap; + } + + @Override + public void onPaint(Graphics g) { + final int BORDER_COLOR = Color.interpolateA(0x869699, this.backColor, 65); + + g.foreColor = BORDER_COLOR; + g.backColor = this.backColor; + g.fillRoundRect(r.x, r.y, r.width, r.height, 10); + + final int yPart = (r.height - xTextHeight - 1) / (yCount + 1); + + for (int i = 0; i < yCount; i++) { + final String s = Integer.toString(i * yStep); + final int yPos = r.height - xTextHeight - 1 - (i + 1) * yPart; + g.foreColor = BORDER_COLOR; + g.drawLine(r.x, yPos, r.width - yTextLen - yGap, yPos); + + g.foreColor = 0xc5cbce; + g.drawLine(r.width - 1 - yTextLen, yPos, r.width - 1 - yTextLen - yGap, yPos); + g.drawText(Convert.toCurrencyString(s, 0), r.width - 1 - yTextLen, yPos - this.fmH / 2); + } + g.foreColor = 0xc5cbce; + g.drawLine(r.width - 1 - yTextLen - yGap, r.y + 1, r.width - 1 - yTextLen - yGap, r.height - xTextHeight - 1); + + // x axis + g.drawLine(r.x + 1, r.height - xTextHeight - 1, r.width - 1 - yTextLen - yGap, r.height - xTextHeight - 1); + + for (int i = 0; i < series.length; i++) { + final Series series2 = series[i]; + g.foreColor = 0xc5cbce; + final List> data = series2.data; + final int nPoints = listToDraw.size(); + if (nPoints > 0) { + final int part = widthX / nPoints; + final int[] xPoints = new int[nPoints]; + final int[] yPoints = new int[nPoints]; + + final int h = r.height - xTextHeight - 1 - r.y - 1; + for (int j = 0; j < nPoints; j++) { + final Data series = data.get(listToDraw.get(j)); + + // x + final int xPos = r.x + 1 + j * part; + + final String s = series.x.toString(); + if (s != null) { + g.foreColor = 0xc5cbce; + g.drawLine(xPos, r.height - xTextHeight - 1, xPos, r.height - (xTextHeight * 3 / 4) - 1); + g.drawText(s, xPos - (this.fm.stringWidth(s) / 2), r.height - (xTextHeight * 3 / 4) - 1); + g.foreColor = BORDER_COLOR; + g.drawLine(xPos, r.y + 1, xPos, r.height - xTextHeight - 1); + } + + final double percentage = 1.0 * series.y.intValue() / (yMax - yMin + yStep); + final int yPos = r.height - xTextHeight - 1 - yPart - (int) Math.round((h * percentage)); + + xPoints[j] = xPos; + yPoints[j] = yPos; + } + g.foreColor = series2.color; + g.drawDots(r.x + 1, yPoints[yPoints.length - 1], widthX, yPoints[yPoints.length - 1]); + g.drawPolyline(xPoints, yPoints, nPoints); + + // paint more pixels around to make the line thicker + for (int j = 0; j < nPoints; j++) { + xPoints[j] += 1; + } + g.drawPolyline(xPoints, yPoints, nPoints); + for (int j = 0; j < nPoints; j++) { + xPoints[j] -= 2; + } + g.drawPolyline(xPoints, yPoints, nPoints); + for (int j = 0; j < nPoints; j++) { + xPoints[j] += 1; + yPoints[j] += 1; + } + g.drawPolyline(xPoints, yPoints, nPoints); + for (int j = 0; j < nPoints; j++) { + yPoints[j] -= 2; + } + g.drawPolyline(xPoints, yPoints, nPoints); + + g.foreColor = Color.WHITE; + final String texto = series2.title; + g.drawText(texto, r.x + 10, r.y + 6 + (i * this.fmH)); + g.foreColor = series2.color; + g.drawText(Convert.toCurrencyString(data.get(listToDraw.get(listToDraw.size() - 1)).y.toString(), 0), + r.x + 15 + this.fm.stringWidth(texto), r.y + 6 + (i * this.fmH)); + } + } + } + + public void changeIndex(int index) { + listToDraw.add(index); + + // Getting scale on y Axis + yMaxValue = Integer.MIN_VALUE; + for (Series series2 : series) { + for (Integer i : listToDraw) { + yMaxValue = Math.max(yMaxValue, series2.data.get(i).y.intValue()); + } + } + yMax = ((yMaxValue / yStep) + 2) * yStep; + + // y axis + yTextLen = Math.max(this.fm.stringWidth(Integer.toString(yMax)), this.fm.stringWidth(Integer.toString(yMin))); + yCount = (yMax - yMin) / yStep; + + repaintNow(); + } + + @SafeVarargs + public final void changeSeries(Series... series) { + this.series = series; + + // Getting scale on y Axis + yMaxValue = Integer.MIN_VALUE; + for (Series series2 : series) { + for (Integer i : listToDraw) { + yMaxValue = Math.max(yMaxValue, series2.data.get(i).y.intValue()); + } + } + yMax = ((yMaxValue / yStep) + 2) * yStep; + + // y axis + yTextLen = Math.max(this.fm.stringWidth(Integer.toString(yMax)), this.fm.stringWidth(Integer.toString(yMin))); + yCount = (yMax - yMin) / yStep; + + repaintNow(); + } + + public static class Series, Y extends Number> { + List> data; + public String title; + public int color; + + public Series(List> data) { + this.data = data; + } + } + + public static class Data, Y extends Number> { + X x; + Y y; + + public Data(X x, Y y) { + this.x = x; + this.y = y; + } + } +} diff --git a/home-assistant/src/main/java/com/totalcross/containers/Home.java b/home-assistant/src/main/java/com/totalcross/containers/Home.java new file mode 100644 index 0000000..2c5bcb6 --- /dev/null +++ b/home-assistant/src/main/java/com/totalcross/containers/Home.java @@ -0,0 +1,39 @@ +package com.totalcross.containers; + +import com.totalcross.util.Fonts; +import totalcross.ui.Container; +import totalcross.ui.Label; +import totalcross.ui.font.Font; +import totalcross.util.UnitsConverter; + +public class Home extends Container { + + public Home() { + + } + + public Container homeContainer; + public Label homeLabel, textLabel; + + static final int SIZEC = 100; + + public void initUI() { + + + homeLabel = new Label("TC Home"); + textLabel = new Label("Bem vindo! Você chegou no demo do\n" + "Home Assistant onde mostramos as\n" + + "melhores UIs criados por nossa\n" + "comunidade."); + + homeLabel.setFont(Font.getFont(Fonts.FONT_DEFAULT, true, 20)); + textLabel.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 15)); + setBorderStyle(BORDER_RAISED); + setBackColor(0xFFFFFF); + add(homeLabel, LEFT + 10, TOP); + add(textLabel, LEFT + 10, AFTER + 20); + + //homeContainer.setRect(LEFT + 10, TOP + UnitsConverter.toPixels(DP + SIZEC), PREFERRED, PREFERRED); + this.resize(); + + } + +} diff --git a/home-assistant/src/main/java/com/totalcross/containers/HomeMap.java b/home-assistant/src/main/java/com/totalcross/containers/HomeMap.java new file mode 100644 index 0000000..22c71ef --- /dev/null +++ b/home-assistant/src/main/java/com/totalcross/containers/HomeMap.java @@ -0,0 +1,287 @@ +package com.totalcross.containers; +import totalcross.ui.gfx.Color; +import com.totalcross.util.Colors; +import com.totalcross.util.Fonts; +import com.totalcross.util.Images; + +import totalcross.sys.Vm; +import totalcross.ui.Button; +import totalcross.ui.Container; +import totalcross.ui.ImageControl; +import totalcross.ui.font.Font; + +public class HomeMap extends Container { + public Container homeMap; + public Button btnLRoom; + public Button btnKitchen; + public Button btnGarage; + public Button btnLigthExternal; + public Button btnDBell; + + private OnUpdateListener upd; + + public Button btnCamera1; + public Button btnCamera2; + public Button btnCamera3; + public Button btnCamera4; + + public boolean isSwitchKitchen() { + return switchKitchen; + } + + public void setSwitchKitchen(boolean switchKitchen) { + this.switchKitchen = switchKitchen; + } + + public boolean isSwitchLRoom() { + return switchLRoom; + } + + public void setSwitchLRoom(boolean switchLRoom) { + this.switchLRoom = switchLRoom; + } + + public boolean isSwitchGarage() { + return switchGarage; + } + + public void setSwitchGarage(boolean switchGarage) { + this.switchGarage = switchGarage; + } + + public boolean isSwitchPorch() { + return switchPorch; + } + + public void setSwitchPorch(boolean switchPorch) { + this.switchPorch = switchPorch; + } + + public boolean isSwitchExternal() { + return switchExternal; + } + + public void setSwitchExternal(boolean switchExternal) { + this.switchExternal = switchExternal; + } + + private boolean switchKitchen = false; + private boolean switchLRoom = false; + private boolean switchGarage= false; + private boolean switchPorch= false; + private boolean switchExternal = false; + + public Button btnTempLadder; + public Button btnTempRoom; + + public ImageControl imgMap; + + static final int SIZEC = 100; + + public String tempLadder = "21°C"; + public String tempRoom = "21°C"; + + private Lights lights; + + + @Override + public void initUI() { + + try { + + Images.loadMap(); + + imgMap = new ImageControl(Images.imgMap); + + btnLRoom = new Button(Images.imgLigthBack); + btnKitchen= new Button(Images.imgLigthBack); + btnGarage = new Button(Images.imgLigthBack); + btnDBell = new Button(Images.imgLigthBack); + btnLigthExternal = new Button(Images.imgLigthBack); + + btnCamera1 = new Button(Images.imgCameraDireita); + btnCamera2 = new Button(Images.imgCameraEsquerda); + btnCamera3 = new Button(Images.imgCameraEsquerda); + btnCamera4 = new Button(Images.imgCameraDireita); + + btnTempLadder = new Button(tempLadder); + btnTempRoom = new Button(tempRoom); + + btnLRoom.transparentBackground = true; + btnKitchen.transparentBackground = true; + btnGarage.transparentBackground = true; + btnDBell.transparentBackground = true; + btnLigthExternal.transparentBackground = true; + + btnCamera1.transparentBackground = true; + btnCamera2.transparentBackground = true; + btnCamera3.transparentBackground = true; + btnCamera4.transparentBackground = true; + + btnLRoom.setBorder(BORDER_NONE); + btnKitchen.setBorder(BORDER_NONE); + btnGarage.setBorder(BORDER_NONE); + btnDBell.setBorder(BORDER_NONE); + btnLigthExternal.setBorder(BORDER_NONE); + + btnCamera1.setBorder(BORDER_NONE); + btnCamera2.setBorder(BORDER_NONE); + btnCamera3.setBorder(BORDER_NONE); + btnCamera4.setBorder(BORDER_NONE); + + btnTempLadder.setBackForeColors(Color.BLACK, Color.WHITE); + btnTempRoom.setBackForeColors(Color.BLACK, Color.WHITE); + + btnTempLadder.setForeColor(Color.WHITE); + btnTempRoom.setForeColor(Color.WHITE); + + btnTempLadder.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 20)); + btnTempRoom.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 20)); + + btnTempLadder.setBorder(BORDER_ROUNDED); + btnTempRoom.setBorder(BORDER_ROUNDED); + + add(imgMap,CENTER,CENTER); + + add(btnLRoom,CENTER - 5,TOP + 130); + add(btnGarage,CENTER + 110,CENTER + 70); + add(btnKitchen,CENTER - 170,CENTER - 50); + add(btnDBell,CENTER - 130,CENTER + 210); + add(btnLigthExternal,CENTER + 140,CENTER + 170); + + add(btnCamera1,CENTER - 190,CENTER - 165); + add(btnCamera2,CENTER + 184,CENTER - 165); + add(btnCamera3,CENTER + 184,CENTER + 165); + add(btnCamera4,CENTER - 190,CENTER + 205); + + add(btnTempLadder,CENTER - 5,CENTER - 35,43,43); + add(btnTempRoom,CENTER - 8,CENTER + 150,43,43); + + // Configurando o container + setBackColor(Colors.BACKGROUD_DEFAULT); + setBorderRadius(5); + setBorderStyle(BORDER_RAISED); + setBackColor(Color.WHITE); + + this.resize(); + + } catch (Exception e) { + Vm.debug(e.toString()); + //e.printStackTrace(); + } + ActionButtonHome(); + + + } + + public void setLights(Lights lights){ + this.lights = lights; + lights.setOnUpdate(()->{ + if(this.lights.isSwtK() == true){ + btnKitchen.setImage(Images.imgLigthYellow); + btnKitchen.transparentBackground = true; + }else{ + btnKitchen.setImage(Images.imgLigthBack); + btnKitchen.transparentBackground = true; + } + if(this.lights.isSwtG() == true){ + btnGarage.setImage(Images.imgLigthYellow); + btnGarage.transparentBackground = true; + }else{ + btnGarage.setImage(Images.imgLigthBack); + btnGarage.transparentBackground = true; + } + if(this.lights.isSwtLR() == true){ + btnLRoom.setImage(Images.imgLigthYellow); + btnLRoom.transparentBackground = true; + }else{ + btnLRoom.setImage(Images.imgLigthBack); + btnLRoom.transparentBackground = true; + } + if(this.lights.isSwtP() == true){ + btnDBell.setImage(Images.imgLigthYellow); + btnDBell.transparentBackground = true; + }else{ + btnDBell.setImage(Images.imgLigthBack); + btnDBell.transparentBackground = true; + } + + + }); + + } + + public void setOnUpdate(OnUpdateListener upd){ + this.upd = upd; + } + //controle de luzes + public void ActionButtonHome(){ + btnLRoom.addPressListener((event) -> { + if(switchLRoom == false){ + btnLRoom.setImage(Images.imgLigthYellow); + btnLRoom.transparentBackground = true; + switchLRoom = true; + upd.onUpdate(); + }else{ + btnLRoom.setImage(Images.imgLigthBack); + btnLRoom.transparentBackground = true; + switchLRoom = false; + upd.onUpdate(); + } + }); + + btnKitchen.addPressListener((event) -> { + if(switchKitchen == false){ + btnKitchen.setImage(Images.imgLigthYellow); + btnKitchen.transparentBackground = true; + switchKitchen = true; + upd.onUpdate(); + }else{ + btnKitchen.setImage(Images.imgLigthBack); + btnKitchen.transparentBackground = true; + switchKitchen = false; + upd.onUpdate(); + } + + + }); + btnGarage.addPressListener((event) -> { + if(switchGarage == false){ + btnGarage.setImage(Images.imgLigthYellow); + btnGarage.transparentBackground = true; + switchGarage = true; + upd.onUpdate(); + }else{ + btnGarage.setImage(Images.imgLigthBack); + btnGarage.transparentBackground = true; + switchGarage = false; + upd.onUpdate(); + } + }); + btnLigthExternal.addPressListener((event) -> { + if(switchExternal == false){ + btnLigthExternal.setImage(Images.imgLigthYellow); + btnLigthExternal.transparentBackground = true; + switchExternal = true; + + }else{ + btnLigthExternal.setImage(Images.imgLigthBack); + btnLigthExternal.transparentBackground = true; + switchExternal = false; + } + }); + btnDBell.addPressListener((event) -> { + if(switchPorch == false){ + btnDBell.setImage(Images.imgLigthYellow); + btnDBell.transparentBackground = true; + switchPorch = true; + upd.onUpdate(); + }else{ + btnDBell.setImage(Images.imgLigthBack); + btnDBell.transparentBackground = true; + switchPorch = false; + upd.onUpdate(); + } + }); + } +} diff --git a/home-assistant/src/main/java/com/totalcross/containers/Info.java b/home-assistant/src/main/java/com/totalcross/containers/Info.java new file mode 100644 index 0000000..e75dacf --- /dev/null +++ b/home-assistant/src/main/java/com/totalcross/containers/Info.java @@ -0,0 +1,100 @@ +package com.totalcross.containers; + +import com.totalcross.util.Colors; +import com.totalcross.util.Fonts; + +import totalcross.ui.Container; +import totalcross.ui.Label; +import totalcross.ui.font.Font; +import totalcross.ui.icon.Icon; +import totalcross.ui.icon.MaterialIcons; + +public class Info extends Container { + public Info() { + + } + + public Container info; + + public Label lblInfo; + public Label lblGngHome; + public Label lblGngWork; + public Label lblPlexSpy; + public Label lblDolarconv; + public Label tempGHome; + public Label tempGWork; + public Label watchspy; + public Label dlconv; + + public Icon gWorkIcon; + public Icon gHomeIcon; + public Icon spyIcon; + public Icon dolarConvIcon; + + static final int SIZEC = 100; + + public void initUI() { + // configurar container + info = new Container(); + info.setBackColor(Colors.BACKGROUD_DEFAULT); + info.setBorderStyle(BORDER_RAISED); + info.setBorderRadius(5); + + add(info, CENTER, TOP, 200, 200); + + // configurar label + lblInfo = new Label("Informação"); + lblGngHome = new Label("indo para Casa"); + lblGngWork = new Label("indo para o Trabalho"); + lblPlexSpy = new Label("PlexSpy"); + lblDolarconv = new Label("USDREAL"); + tempGHome = new Label("40 min "); + tempGWork = new Label("37 min "); + watchspy = new Label("0 Watching "); + dlconv = new Label("5,22 R$ "); + + lblInfo.setFont(Font.getFont(Fonts.FONT_DEFAULT, true, lblInfo.getFont().size + 10)); + lblGngHome.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 14)); + lblGngWork.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 14)); + lblPlexSpy.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 14)); + lblDolarconv.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 14)); + tempGHome.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 14)); + tempGWork.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 14)); + watchspy.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 14)); + dlconv.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 14)); + + // configurar icone + gWorkIcon = new Icon(MaterialIcons._DIRECTIONS_CAR); + gHomeIcon = new Icon(MaterialIcons._DIRECTIONS_CAR); + spyIcon = new Icon(MaterialIcons._VISIBILITY); + dolarConvIcon = new Icon(MaterialIcons._ATTACH_MONEY); + + gHomeIcon.setForeColor(0x6495ED); + gWorkIcon.setForeColor(0x6495ED); + spyIcon.setForeColor(0x6495ED); + dolarConvIcon.setForeColor(0x6495ED); + + info.add(lblInfo, LEFT + 10, TOP); + + info.add(gWorkIcon, LEFT + 10, CENTER - 30); + info.add(lblGngWork, LEFT + 50, CENTER - 30); + info.add(tempGWork, RIGHT + 30, CENTER - 30); + + info.add(gHomeIcon, LEFT + 10, CENTER); + info.add(lblGngHome, LEFT + 50, CENTER); + info.add(tempGHome, RIGHT + 30, CENTER); + + info.add(spyIcon, LEFT + 8, CENTER + 30); + info.add(lblPlexSpy, LEFT + 50, CENTER + 30); + info.add(watchspy, RIGHT + 30, CENTER + 30); + + info.add(dolarConvIcon, LEFT + 12, BOTTOM - 30); + info.add(lblDolarconv, LEFT + 50, BOTTOM - 30); + info.add(dlconv, RIGHT + 30, BOTTOM - 30); + + info.setRect(CENTER, TOP, PREFERRED, PREFERRED); + info.resize(); + + } + +} \ No newline at end of file diff --git a/home-assistant/src/main/java/com/totalcross/containers/Lights.java b/home-assistant/src/main/java/com/totalcross/containers/Lights.java new file mode 100644 index 0000000..f5b25b5 --- /dev/null +++ b/home-assistant/src/main/java/com/totalcross/containers/Lights.java @@ -0,0 +1,318 @@ +package com.totalcross.containers; + +import com.totalcross.util.Colors; +import com.totalcross.util.Fonts; + + +import totalcross.ui.Container; +import totalcross.ui.Label; +import totalcross.ui.Switch; +import totalcross.ui.font.Font; +import totalcross.ui.icon.Icon; +import totalcross.ui.icon.MaterialIcons; + + +public class Lights extends Container { + + public Lights() { + + } + private OnUpdateListener upd; + + public static boolean kValue; + public static boolean gValue; + public static boolean lrValue; + public static boolean pValue; + public static boolean lValue; + + public boolean isSwtK() { + return swtK; + } + + public void setSwtK(boolean swtK) { + this.swtK = swtK; + } + + public boolean isSwtLR() { + return swtLR; + } + + public void setSwtLR(boolean swtLR) { + this.swtLR = swtLR; + } + + public boolean isSwtG() { + return swtG; + } + + public void setSwtG(boolean swtG) { + this.swtG = swtG; + } + + public boolean isSwtP() { + return swtP; + } + + public void setSwtP(boolean swtP) { + this.swtP = swtP; + } + + private boolean swtK; + private boolean swtLR; + private boolean swtG; + private boolean swtP; + + + public Container lightCtrl; + public Label lblLights; + public Label lblKitchenl; + public Label lblLRooml; + public Label lblPorchl; + public Label lblGaragel; + + public Switch sLights; + public Switch sKitchen; + public Switch slRoom; + public Switch sPorch; + public Switch sGarage; + + public Icon kitchenLIcon; + public Icon lRoomLIcon; + public Icon porchLIcon; + public Icon garageLIcon; + + static final int SIZEC = 100; + + private HomeMap homeMap; + + public void initUI() { + + + + //lightCtrl = new Container(); + setBackColor(Colors.BACKGROUD_DEFAULT); + setBorderStyle(BORDER_RAISED); + + //add(lightCtrl, CENTER, CENTER, 300, 300); + + // Material Icons + kitchenLIcon = new Icon(MaterialIcons._LIGHTBULB_OUTLINE); + lRoomLIcon = new Icon(MaterialIcons._LIGHTBULB_OUTLINE); + porchLIcon = new Icon(MaterialIcons._FLASH_ON); + garageLIcon = new Icon(MaterialIcons._LIGHTBULB_OUTLINE); + + // Criando Switch button + sLights = new Switch(); + sKitchen = new Switch(); + slRoom = new Switch(); + sPorch = new Switch(); + sGarage = new Switch(); + + // configurando labels + lblLights = new Label("Lights"); + lblKitchenl = new Label("Kitchen"); + lblLRooml = new Label("Living Room"); + lblPorchl = new Label("Porch"); + lblGaragel = new Label("Garage"); + + lblLights.setFont(Font.getFont(Fonts.FONT_DEFAULT, true, lblLights.getFont().size + 10)); + lblKitchenl.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 15)); + lblLRooml.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 15)); + lblPorchl.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 15)); + lblGaragel.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 15)); + + // configurando icones + + kitchenLIcon.setForeColor(0x6495ED); + lRoomLIcon.setForeColor(0x6495ED); + porchLIcon.setForeColor(0x6495ED); + garageLIcon.setForeColor(0x6495ED); + + // configurando switch button + sLights.colorBackOn = 0x00BFFF; + sLights.colorBackOff = Colors.COLOR_DARK_GRAY; + sLights.colorBallOn = 0x1E90FF; + sLights.colorBallOff = 0x696969; + + sKitchen.colorBackOn = 0x00BFFF; + sKitchen.colorBackOff = Colors.COLOR_DARK_GRAY; + sKitchen.colorBallOn = 0x1E90FF; + sKitchen.colorBallOff = 0x696969; + + slRoom.colorBackOn = 0x00BFFF; + slRoom.colorBackOff = Colors.COLOR_DARK_GRAY; + slRoom.colorBallOn = 0x1E90FF; + slRoom.colorBallOff = 0x696969; + + sPorch.colorBackOn = 0x00BFFF; + sPorch.colorBackOff = Colors.COLOR_DARK_GRAY; + sPorch.colorBallOn = 0x1E90FF; + sPorch.colorBallOff = 0x696969; + + sGarage.colorBackOn = 0x00BFFF; + sGarage.colorBackOff = Colors.COLOR_DARK_GRAY; + sGarage.colorBallOn = 0x1E90FF; + sGarage.colorBallOff = 0x696969; + + // adicionado ao container + add(lblLights, LEFT + 10, TOP); + add(sLights, AFTER + 113, SAME); + + add(kitchenLIcon, LEFT + 10, AFTER + 30); + add(lblKitchenl, AFTER, SAME, DP + 150, PREFERRED); + add(sKitchen, AFTER, SAME); + + add(lRoomLIcon, LEFT + 10, AFTER + 10); + add(lblLRooml,AFTER, SAME, DP + 150, PREFERRED); + add(slRoom, AFTER, SAME); + + add(porchLIcon, LEFT + 10, AFTER +10); + add(lblPorchl, AFTER, SAME, DP + 150, PREFERRED); + add(sPorch, AFTER, SAME); + + add(garageLIcon, LEFT + 10, AFTER + 10); + add(lblGaragel, AFTER, SAME, DP + 150, PREFERRED); + add(sGarage, AFTER, SAME); + + + homeMap = new HomeMap(); + + turnOnOff(); + + + } + //controle de luzes + public void turnOnOff(){ + sLights.addPressListener((event) -> { + if (sLights.isOn()) { + sKitchen.setOn(true); + slRoom.setOn(true); + sGarage.setOn(true); + sPorch.setOn(true); + + swtK = true; + swtLR = true; + swtG = true; + swtP = true; + + kitchenLIcon.setForeColor(0xFFFF00); + lRoomLIcon.setForeColor(0xFFFF00); + porchLIcon.setForeColor(0xFFFF00); + garageLIcon.setForeColor(0xFFFF00); + upd.onUpdate(); + } else if (sLights.isOn() == false) { + sKitchen.setOn(false); + kitchenLIcon.setForeColor(0x6495ED); + slRoom.setOn(false); + lRoomLIcon.setForeColor(0x6495ED); + sGarage.setOn(false); + garageLIcon.setForeColor(0x6495ED); + sPorch.setOn(false); + porchLIcon.setForeColor(0x6495ED); + + swtK = false; + swtLR = false; + swtG = false; + swtP = false; + upd.onUpdate(); + + } + }); + sKitchen.addPressListener((event) -> { + if (sKitchen.isOn()) { + kitchenLIcon.setForeColor(0xFFFF00); + swtK = true; + upd.onUpdate(); + } else{ + kitchenLIcon.setForeColor(0x6495ED); + swtK = false; + upd.onUpdate(); + } + }); + slRoom.addPressListener((event) -> { + if (slRoom.isOn()) { + lRoomLIcon.setForeColor(0xFFFF00); + + swtLR = true; + upd.onUpdate(); + } else { + lRoomLIcon.setForeColor(0x6495ED); + + swtLR = false; + upd.onUpdate(); + } + }); + sGarage.addPressListener((event) -> { + if (sGarage.isOn()) { + garageLIcon.setForeColor(0xFFFF00); + swtG = true; + + upd.onUpdate(); + } else{ + garageLIcon.setForeColor(0x6495ED); + + swtG = false; + upd.onUpdate(); + } + }); + sPorch.addPressListener((event) -> { + if (sPorch.isOn()) { + porchLIcon.setForeColor(0xFFFF00); + + swtP = true; + upd.onUpdate(); + } else { + porchLIcon.setForeColor(0x6495ED); + + swtP = false; + upd.onUpdate(); + } + }); + } + //set home map + public void setHomeMap(HomeMap homeMap){ + this.homeMap = homeMap; + homeMap.setOnUpdate(()->{ + kValue = this.homeMap.isSwitchKitchen(); + sKitchen.setOn(kValue); + if (kValue == true) { + kitchenLIcon.setForeColor(0xFFFF00); + swtK = true; + } else{ + kitchenLIcon.setForeColor(0x6495ED); + swtK = false; + } + lrValue = this.homeMap.isSwitchLRoom(); + slRoom.setOn(lrValue); + if (lrValue == true) { + lRoomLIcon.setForeColor(0xFFFF00); + swtLR = true; + } else { + lRoomLIcon.setForeColor(0x6495ED); + swtLR = false; + } + gValue = this.homeMap.isSwitchGarage(); + sGarage.setOn(gValue); + if (gValue == true) { + garageLIcon.setForeColor(0xFFFF00); + swtG = true; + } else{ + garageLIcon.setForeColor(0x6495ED); + swtG = false; + } + pValue = this.homeMap.isSwitchPorch(); + sPorch.setOn(pValue); + if (pValue == true) { + porchLIcon.setForeColor(0xFFFF00); + swtP = true; + } else { + porchLIcon.setForeColor(0x6495ED); + swtP = false; + } + }); + } + //update Listener + public void setOnUpdate(OnUpdateListener upd){ + this.upd = upd; + } +} \ No newline at end of file diff --git a/home-assistant/src/main/java/com/totalcross/containers/MainActivity.java b/home-assistant/src/main/java/com/totalcross/containers/MainActivity.java new file mode 100644 index 0000000..aa35093 --- /dev/null +++ b/home-assistant/src/main/java/com/totalcross/containers/MainActivity.java @@ -0,0 +1,77 @@ +package com.totalcross.containers; + +import totalcross.ui.ScrollContainer; + +public class MainActivity extends ScrollContainer{ + + Home home; + Temperature temperature; + Security security; + TemperatureStudy temperatureStudy; + HomeMap homeMap; + Spotify spotify; + Demo demo; + ScrollContainer container; + Lights lights; + Info info; + Notify notification; + Energy energy; + Entertainment entertainment; + DoorBell doorBell; + + @Override + public void initUI() { + + setScrollBars(false, true); + setBackForeColors(0xF7F7F7, 0x000000); + + home = new Home(); + add(home, LEFT, TOP,PREFERRED,PREFERRED); + home.resize(); + + homeMap = new HomeMap(); + add(homeMap,SAME,AFTER, 410, 489,home); + homeMap.resize(); + + security = new Security(); + add(security,AFTER,SAME,PREFERRED,PREFERRED,home); + security.resize(); + + spotify = new Spotify(); + add(spotify,AFTER - 22,SAME - 40, 300,200,security); + spotify.resize(); + + temperature = new Temperature(); + add(temperature, SAME, AFTER,PREFERRED,PREFERRED,homeMap); + temperature.resize(); + + info = new Info(); + add(info,AFTER, SAME,PREFERRED,PREFERRED,temperature); + info.resize(); + + temperatureStudy = new TemperatureStudy(); + add(temperatureStudy,SAME, AFTER,PREFERRED,PREFERRED,info); + temperatureStudy.resize(); + + entertainment = new Entertainment(); + add(entertainment,AFTER, SAME,PREFERRED,PREFERRED,homeMap); + entertainment.resize(); + + energy = new Energy(); + add(energy, AFTER,SAME,PREFERRED,PREFERRED,info); + energy.resize(); + + doorBell = new DoorBell(); + add(doorBell, SAME,AFTER,PREFERRED,PREFERRED,temperature); + doorBell.resize(); + + lights = new Lights(); + add(lights, SAME + 10, AFTER,PREFERRED,PREFERRED,temperatureStudy); + lights.resize(); + + homeMap.setLights(lights); + lights.setHomeMap(homeMap); + } +} + + diff --git a/home-assistant/src/main/java/com/totalcross/containers/Map.java b/home-assistant/src/main/java/com/totalcross/containers/Map.java new file mode 100644 index 0000000..bc00b6f --- /dev/null +++ b/home-assistant/src/main/java/com/totalcross/containers/Map.java @@ -0,0 +1,7 @@ +package com.totalcross.containers; + +import totalcross.ui.Container; + +public class Map extends Container{ + +} diff --git a/home-assistant/src/main/java/com/totalcross/containers/Notify.java b/home-assistant/src/main/java/com/totalcross/containers/Notify.java new file mode 100644 index 0000000..a456f90 --- /dev/null +++ b/home-assistant/src/main/java/com/totalcross/containers/Notify.java @@ -0,0 +1,63 @@ +package com.totalcross.containers; + +import com.totalcross.util.Colors; +import totalcross.ui.Button; +import totalcross.ui.Container; +import totalcross.ui.Label; +import totalcross.ui.ScrollContainer; +import totalcross.ui.gfx.Color; + +public class Notify extends ScrollContainer { + + public Container ContainerMensagem; + + public Label lblTitle; + public Label lblMensagem; + public Label lblTime; + + public Button exit; + + @Override + public void initUI() { + + setScrollBars(false, true); + setBackForeColors(0xF7F7F7, 0x000000); + + ContainerMensagem = new Container(); + + lblTitle = new Label("Motion Detected!"); + lblMensagem = new Label("There was motion detected in the backyard."); + lblTime = new Label("5 horas atrás"); + + exit = new Button("DISPENSAR"); + + lblTitle.transparentBackground = true; + lblMensagem.transparentBackground = true; + lblTime.transparentBackground = true; + + /* lblTitle.setFont(Font.getFont(Fonts.FONT_DEFAULT, true, 20)); + lblMensagem.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 10)); + lblTime.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, 10)); */ + + /* lblTitle.setBackColor(Color.BLACK); + lblMensagem.setBackColor(Color.BLACK); + lblTime.setBackColor(Color.BLACK); */ + + add(ContainerMensagem,CENTER,CENTER); + + ContainerMensagem.add(lblTitle, LEFT + 10 , TOP + 10); + ContainerMensagem.add(lblMensagem, LEFT + 10 , AFTER + 10); + ContainerMensagem.add(lblTime, LEFT + 80 , AFTER + 10); + ContainerMensagem.add(exit, LEFT + 10 , AFTER + 10); + + // Configurando o container + setBackColor(Colors.BACKGROUD_DEFAULT); + setBorderRadius(5); + setBorderStyle(BORDER_RAISED); + setBackColor(Color.WHITE); + + // setRect(CENTER,CENTER, KEEP, KEEP); + this.resize(); + + } +} diff --git a/home-assistant/src/main/java/com/totalcross/containers/OnUpdateListener.java b/home-assistant/src/main/java/com/totalcross/containers/OnUpdateListener.java new file mode 100644 index 0000000..8db00f6 --- /dev/null +++ b/home-assistant/src/main/java/com/totalcross/containers/OnUpdateListener.java @@ -0,0 +1,5 @@ +package com.totalcross.containers; + +public interface OnUpdateListener { + public void onUpdate(); +} diff --git a/home-assistant/src/main/java/com/totalcross/containers/Security.java b/home-assistant/src/main/java/com/totalcross/containers/Security.java new file mode 100644 index 0000000..66ca9d6 --- /dev/null +++ b/home-assistant/src/main/java/com/totalcross/containers/Security.java @@ -0,0 +1,95 @@ +package com.totalcross.containers; + +import com.totalcross.util.Colors; +import com.totalcross.util.Fonts; +import com.totalcross.util.Images; +import totalcross.ui.Button; +import totalcross.ui.Container; +import totalcross.ui.ImageControl; +import totalcross.ui.Label; +import totalcross.ui.font.Font; +import totalcross.ui.gfx.Color; + + + +public class Security extends Container{ + + public Label lblTitle; + + public Button btnSecurityHome; + public Button btnSecurityStatus; + public Button btnSecuritStop; + + public ImageControl imgSecurity; + + static final int SIZEC = 100; + + @Override + public void initUI() { + Images.loadSecurity(); + + //Criando label security + lblTitle = new Label("Security"); + + //Criando imagem + imgSecurity = new ImageControl(Images.imgSecurityGreen); + + //Criando buttons + btnSecurityStatus = new Button("Armar Ausente"); + btnSecurityHome = new Button("Armar em Casa"); + btnSecuritStop = new Button("DESARMAR"); + + //Configurando Botões + btnSecurityHome.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, btnSecurityHome.getFont().size + 1)); + btnSecurityStatus.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, btnSecurityStatus.getFont().size + 1)); + btnSecuritStop.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, btnSecuritStop.getFont().size + 1)); + + //Configurando label + lblTitle.transparentBackground = true; + lblTitle.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, lblTitle.getFont().size + 10)); + + // Configurando o container + setBackColor(Colors.BACKGROUD_DEFAULT); + setBorderRadius(5); + setBorderStyle(BORDER_RAISED); + setBackColor(Color.WHITE); + + + add(lblTitle, LEFT + 20, TOP + 10 ); + add(imgSecurity, LEFT + 200, SAME); + add(btnSecurityHome, LEFT + 10, SAME + 62); + add(btnSecurityStatus, SAME + 140, SAME); + add(btnSecuritStop, LEFT + 90, TOP + 70); + + btnSecuritStop.setVisible(false); + this.resize(); + + ActionButton(); + } + + public void ActionButton(){ + + btnSecurityHome.addPressListener((event) -> { + imgSecurity.setImage( btnSecurityHome.isPressed() ? Images.imgSecurityGreen:Images.imgSecurityRed); + btnSecurityHome.setVisible(false); + btnSecurityStatus.setVisible(false); + btnSecuritStop.setVisible(true); + }); + + btnSecurityStatus.addPressListener((event) -> { + imgSecurity.setImage( btnSecurityHome.isPressed() ? Images.imgSecurityGreen:Images.imgSecurityRed); + btnSecurityHome.setVisible(false); + btnSecurityStatus.setVisible(false); + btnSecuritStop.setVisible(true); + }); + + btnSecuritStop.addPressListener((event) -> { + imgSecurity.setImage(!btnSecurityHome.isPressed()? Images.imgSecurityGreen:Images.imgSecurityRed); + btnSecurityHome.setVisible(true); + btnSecurityStatus.setVisible(true); + btnSecuritStop.setVisible(false); + }); + } +} + + diff --git a/home-assistant/src/main/java/com/totalcross/containers/SideMenu.java b/home-assistant/src/main/java/com/totalcross/containers/SideMenu.java new file mode 100644 index 0000000..282b050 --- /dev/null +++ b/home-assistant/src/main/java/com/totalcross/containers/SideMenu.java @@ -0,0 +1,57 @@ +package com.totalcross.containers; + +import com.totalcross.util.Colors; + +import totalcross.ui.Container; +import totalcross.ui.Label; +import totalcross.ui.SideMenuContainer; +import totalcross.ui.font.Font; +import totalcross.ui.gfx.Color; +import totalcross.ui.icon.Icon; +import totalcross.ui.icon.MaterialIcons; + +public class SideMenu extends Container { + + public void initUI(){ + + SideMenuContainer.Item home = new SideMenuContainer.Item("Home", MaterialIcons._HOME, Color.DARK, () -> {return new MainActivity ();}); + SideMenuContainer.Item energy = new SideMenuContainer.Item("Energy", MaterialIcons._POWER, Color.DARK, ()-> {return new EnergyMenu();}); + SideMenuContainer.Item map = new SideMenuContainer.Item("Map", MaterialIcons._MAP, Color.DARK, ()-> {return new Energy();}); + SideMenuContainer.Item demo = new SideMenuContainer.Item("Demo", MaterialIcons._ACCESSIBILITY, Color.DARK, ()-> {return new Demo();}); + SideMenuContainer.Item notify = new SideMenuContainer.Item("Notificação", MaterialIcons._NOTIFICATIONS, Color.DARK, ()-> {return new Notify();}); + + SideMenuContainer sideMenu = new SideMenuContainer( + null, + home, + energy, + map, + notify, + demo); + + sideMenu.topMenu.header = new Container(){ + public void initUI(){ + setBackColor(Colors.FROZEN_DEFAULT); + + Label title = new Label("Home Assistant", CENTER, Color.WHITE, false); + title.setFont(Font.getFont(Font.DEFAULT, true, this.getFont().size+6)); + title.setForeColor(Color.WHITE); + add(title, LEFT+25, BOTTOM-45, PARENTSIZE+40, DP+56); + } + }; + + sideMenu.setBarFont(Font.getFont(Font.getDefaultFontSize()+2)); + sideMenu.setBackColor(0x4A90E2); + sideMenu.setForeColor(Color.WHITE); + sideMenu.setItemForeColor(Color.BLACK); + sideMenu.topMenu.drawSeparators = false; + sideMenu.topMenu.itemHeightFactor = 3; + + Icon icon = new Icon(MaterialIcons._MENU); + icon.setBackColor(Color.BLACK); + add(icon, CENTER + 20, TOP + 20); + add(sideMenu, LEFT, TOP, PARENTSIZE, PARENTSIZE); + } + +} + + diff --git a/home-assistant/src/main/java/com/totalcross/containers/Spotify.java b/home-assistant/src/main/java/com/totalcross/containers/Spotify.java new file mode 100644 index 0000000..0ac55d0 --- /dev/null +++ b/home-assistant/src/main/java/com/totalcross/containers/Spotify.java @@ -0,0 +1,35 @@ +package com.totalcross.containers; + +import com.totalcross.util.*; +import totalcross.ui.Container; +import totalcross.util.UnitsConverter; +import totalcross.ui.ImageControl; + +public class Spotify extends Container{ + + public Container spotify; + + public ImageControl imgSpotify; + + static final int SIZEC = 100; + + @Override + public void initUI() { + + Images.loadSpotify(); + + spotify = new Container(); + add(spotify, CENTER, TOP + UnitsConverter.toPixels(DP + 30)); + + imgSpotify = new ImageControl(Images.imgSpotify); + + // imgSpotify.scaleToFit = true; + // imgSpotify.strechImage = true; + + add(imgSpotify, CENTER,CENTER); + + spotify.transparentBackground = true; + + this.resize(); + } +} diff --git a/home-assistant/src/main/java/com/totalcross/containers/Temperature.java b/home-assistant/src/main/java/com/totalcross/containers/Temperature.java new file mode 100644 index 0000000..d8769fa --- /dev/null +++ b/home-assistant/src/main/java/com/totalcross/containers/Temperature.java @@ -0,0 +1,104 @@ +package com.totalcross.containers; + +import com.totalcross.util.Colors; +import com.totalcross.util.Fonts; +import com.totalcross.util.Images; +import totalcross.ui.Button; +import totalcross.ui.Container; +import totalcross.ui.Label; +import totalcross.ui.Slider; +import totalcross.ui.font.Font; +import totalcross.ui.gfx.Color; + +public class Temperature extends Container { + + public Label lblLevel; + public Label lblTempNow; + public Label lblTemp; + public Label lblStatusTemp; + + public Button btnHot; + public Button btnFrozen; + public Button btnOff; + public Button btnDate; + + public Slider sliderTempMin; + public Slider sliderTempMax; + + public String statusTemp = "Automatico"; + public String statusTempOFF = "Ausente"; + public String tempMax = "30"; + public String tempMin = "15"; + + static final int SIZEC = 100; + public int startAngle = 225; + public int endAngle = 315; + public int radius; + + ArcSlider arcSlider; + + @Override + public void initUI() { + + // Chamando imagens + Images.loadCalender(); + Images.loadFrozen(); + Images.loadHot(); + Images.loadOff(); + + // Criando labels + lblLevel = new Label("Andar de cima"); + lblTempNow = new Label("22°"); + lblTemp = new Label(tempMin + " - " + tempMax); + lblStatusTemp = new Label(statusTemp + " - " + statusTempOFF); + + // Configurando labels + lblTempNow.transparentBackground = true; + lblTemp.transparentBackground = true; + lblStatusTemp.transparentBackground = true; + lblTempNow.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, lblTempNow.getFont().size + 60)); + lblStatusTemp.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, lblStatusTemp.getFont().size + 2)); + lblTemp.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, lblTemp.getFont().size + 2)); + lblLevel.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, lblLevel.getFont().size + 2)); + + // Criando botões + btnDate = new Button(Images.imgCalenderGray); + btnFrozen = new Button(Images.imgCalenderGray); + btnHot = new Button(Images.imgHotGray); + btnOff = new Button(Images.imgOffGray); + + // Criando slider button + arcSlider = new ArcSlider(); + + + // Configurando o container + setBackColor(Colors.BACKGROUD_DEFAULT); + setBorderRadius(5); + setBorderStyle(BORDER_RAISED); + setBackColor(Color.WHITE); + + // Configurando os botoes + btnDate.transparentBackground = true; + btnFrozen.transparentBackground = true; + btnHot.transparentBackground = true; + btnOff.transparentBackground = true; + + // Adicionando componentes ao container + add(arcSlider, LEFT - 10, CENTER + 80, 250, 200); + + add(lblTempNow, LEFT + 75, SAME + 50); + add(lblTemp, SAME + 15, SAME + 80); + add(lblStatusTemp, SAME - 40, SAME + 20); + + add(btnDate, LEFT + 20, SAME + 30); + add(btnHot, SAME + 50, SAME); + add(btnFrozen, SAME + 50, SAME); + add(btnOff, SAME + 50, SAME); + + add(lblLevel, LEFT + 60, SAME + 50); + + // Configurando tamanho do container + //setRect(CENTER, CENTER, PREFERRED, PREFERRED); + resize(); + } +} diff --git a/home-assistant/src/main/java/com/totalcross/containers/TemperatureStudy.java b/home-assistant/src/main/java/com/totalcross/containers/TemperatureStudy.java new file mode 100644 index 0000000..34537d9 --- /dev/null +++ b/home-assistant/src/main/java/com/totalcross/containers/TemperatureStudy.java @@ -0,0 +1,147 @@ +package com.totalcross.containers; + +import com.totalcross.util.Colors; +import com.totalcross.util.Fonts; +import com.totalcross.util.Images; +import totalcross.ui.Container; +import totalcross.ui.ImageControl; +import totalcross.ui.Label; +import totalcross.ui.font.Font; +import totalcross.ui.gfx.Color; +import totalcross.util.UnitsConverter; + + +public class TemperatureStudy extends Container{ + + private static Label lblTitle; + private Label lblTemp; + + private String temp = "20"; + public static String DEFAULT_TEMP = "°C"; + + static final int SIZEC = 100; + + private ImageControl imgEnergy; + + // Graphifc.Series TempGraphifc; + + @Override + public void initUI() { + + Images.loadTemperatureStudy(); + + //Criando imagem + imgEnergy = new ImageControl(Images.imgEnergy); + + //Configurando imagem + imgEnergy.transparentBackground = true; + + //Criando label + lblTitle = new Label("Estudo de temperatura"); + lblTemp = new Label(temp + DEFAULT_TEMP); + + //Configurando label + lblTitle.transparentBackground = true; + lblTemp.transparentBackground = true; + lblTitle.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, lblTitle.getFont().size + 6)); + lblTemp.setFont(Font.getFont(Fonts.FONT_DEFAULT, false, lblTemp.getFont().size + 5)); + + + add(lblTitle, LEFT + 20, TOP + 10); + add(lblTemp, SAME, SAME + 20); + add(imgEnergy, LEFT + 200, TOP + 10); + //temperatureStudy.add(graphicsTemp, LEFT + 20, TOP + 10); + + // Configurando o container + setBackColor(Colors.BACKGROUD_DEFAULT); + setBorderRadius(5); + setBorderStyle(BORDER_RAISED); + setBackColor(Color.WHITE); + + //Configurando container + //setRect(LEFT + 10, TOP + UnitsConverter.toPixels(DP + SIZEC), KEEP, KEEP); + resize(); + +} +/* + class MyDate implements Comparable { + int date; + int day; + int month; + String s = null; + public static final int DAY = 0; + public static final int MONTH = 1; + public static final int WEEK = 2; + public static int mode = DAY; + public Date firstDay; + + public MyDate(int yyyyMMdd) { + this.date = yyyyMMdd; + this.day = this.date % 100; + this.month = yyyyMMdd / 100 % 100; + if (this.day == 1) { + s = Date.monthNames[this.month].substring(0, 3); + } else if (this.day == 10 || this.day == 19) { + s = Integer.toString(this.day); + } + } + + public void changeMode(int mode) { + MyDate.mode = mode; + switch (mode) { + case DAY: + if (this.day == 1) { + s = Date.monthNames[this.month].substring(0, 3); + } else if (this.day == 10 || this.day == 19) { + s = Integer.toString(this.day); + } else { + s = null; + } + break; + case MONTH: + if (this.toDate().equals(firstDay) || this.day == 1) { + s = Date.monthNames[this.month].substring(0, 3); + } else { + s = null; + } + break; + case WEEK: + if (exactlyXWeeksSinceDate(MyDate.firstDay)) { + s = weeksSinceDate(MyDate.firstDay); + } else { + s = null; + } + break; + } + } + + public String weeksSinceDate(Date date) { + return date != null ? Integer.toString(date.subtract(this.toDate()) / 7) : null; + } + + public boolean exactlyXWeeksSinceDate(Date date) { + return date != null ? date.subtract(this.toDate()) % 7 == 0 : false; + } + + public int compareTo(MyDate o) { + return this.date - o.date; + } + + public Date toDate() { + int year = this.date / 10000; + Date myDate = null; + try { + myDate = new Date(year + "-" + this.month + "-" + this.day, Settings.DATE_YMD); + } catch (InvalidDateException e) { + e.printStackTrace(); + } + return myDate; + } + + @Override + public String toString() { + return s; + } + */ +} +//} diff --git a/home-assistant/src/main/java/com/totalcross/database/DAO.java b/home-assistant/src/main/java/com/totalcross/database/DAO.java new file mode 100644 index 0000000..c110a7d --- /dev/null +++ b/home-assistant/src/main/java/com/totalcross/database/DAO.java @@ -0,0 +1,46 @@ +package com.totalcross.database; + +import java.sql.SQLException; +import totalcross.sql.Connection; +import totalcross.sql.PreparedStatement; +import totalcross.sql.ResultSet; +import totalcross.sql.Statement; + +public class DAO { + + /* String Kitchen = "kitchen"; + public void initUI() { + + + String sqlKitchen = "insert into Ligths(idLigth,ligth)" + + "value('?','?');"; + String sqlLivingRoom; + String sqlPorch; + String sqlGarage; + Connection dbcon = DatabaseManager.getConnection(); + PreparedStatement ps = dbcon.prepareStatement(sqlKitchen); + + ps.setString(1, Kitchen); + ps.executeUpdate(); + ps.close(); + + } + public boolean insertCPF(String cpf) throws SQLException { + + boolean success = false; + Connection dbcon = DatabaseManager.getConnection(); + String sql = "insert into person values(?)"; + PreparedStatement ps = dbcon.prepareStatement(sql); + ps.setString(1, cpf); + + int i = ps.executeUpdate(); + ps.close(); + + if (i > 0) { + success = true; + } else { + success = false; + } + return success; + } */ +} diff --git a/home-assistant/src/main/java/com/totalcross/database/DatabaseManager.java b/home-assistant/src/main/java/com/totalcross/database/DatabaseManager.java new file mode 100644 index 0000000..955d2d4 --- /dev/null +++ b/home-assistant/src/main/java/com/totalcross/database/DatabaseManager.java @@ -0,0 +1,161 @@ +package com.totalcross.database; + +import java.sql.SQLException; +import totalcross.db.sqlite.SQLiteUtil; +import totalcross.sql.Statement; +import totalcross.sys.Settings; + +public class DatabaseManager { + + private static DatabaseManager instance = null; + private SQLiteUtil util; + + private DatabaseManager() { + + try { + util = new SQLiteUtil(Settings.appPath,"HomeAssitant.db"); + createTableLigths(); + createTableHistoricLigths(); + createTableHitoricTemp(); + createTableHitoricInfo(); + } catch (SQLException e) { + + e.printStackTrace(); + + } + } + + public static DatabaseManager getInstance() { + + if(instance == null) { + instance = new DatabaseManager(); + } + + return instance; + } + public void createTableLigths() { + + try { + + Statement st = util.con().createStatement(); + st.execute("create table IF NOT EXISTSLigths( " + + "idLigth int primary key auto_increment," + + "ligth varchar(10) not null unique" + + ");"); + + st.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + } + public void createTableHistoricLigths() { + + try { + + Statement st = util.con().createStatement(); + st.execute("create table HistoricLights(" + + "idHistoricLigth int primary key auto_increment," + + "nameLigth varchar (10) not null," + + "foreign key (nameLigth) references Ligths(ligth)," + + "statusLigth varchar(3) not null," + + "dataLigth datetime not null" + + ");"); + + st.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + } + public void createTableHitoricTemp() { + + try { + + Statement st = util.con().createStatement(); + st.execute("create table HistoricTemp(" + + "idTemp int primary key not null unique," + + "Temp int not null unique," + + "dataTemp datetime not null" + + ");"); + + st.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public void createTableHitoricInfo() { + + try { + + Statement st = util.con().createStatement(); + st.execute("create table Info(" + + "idInfo int primary key auto_increment," + + "info varchar (20) not null unique" + + ");"); + + st.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + } + + + +/* public Boolean insertUsers(User user) { + + Boolean success = true; + + try { + + String sql = "INSERT INTO USERS VALUES (?,?,?,?)"; + PreparedStatement st = util.con().prepareStatement(sql); + + st.setString(1, user.getName()); + st.setString(2, user.getPhone()); + st.setString(3, user.getMail()); + st.setString(4, user.getPassword()); + + st.executeUpdate(); + st.close(); + + } catch (SQLException e) { + e.printStackTrace(); + success = false; + } + + return success; + } */ + +/* public ArrayList getUsers() { + + ArrayList users = new ArrayList<>(); + + try { + + Statement st = util.con().createStatement(); + ResultSet rs = st.executeQuery("SELECT * FROM USERS"); + + while (rs.next()){ + + User user = new User(); + user.setName(rs.getString("NAME")); + user.setPhone(rs.getString("PHONE")); + user.setMail(rs.getString("EMAIL")); + user.setPassword(rs.getString("PASSWORD")); + + users.add(user); + + } + + } catch (SQLException e) { + e.printStackTrace(); + } + + return users; + } */ +} + diff --git a/home-assistant/src/main/java/com/totalcross/util/Colors.java b/home-assistant/src/main/java/com/totalcross/util/Colors.java new file mode 100644 index 0000000..2e93aae --- /dev/null +++ b/home-assistant/src/main/java/com/totalcross/util/Colors.java @@ -0,0 +1,16 @@ +package com.totalcross.util; + +public class Colors { + public static final int BACKGROUD_DEFAULT= 0xFFFFFF; + public static final int CALENDER_DEFAULT= 0xa9a9a9; + public static final int TEMPERATURE_DEFAULT= 0x05ae11; + public static final int FROZEN_DEFAULT= 0x14b4dc; + public static final int HOT_DEFAULT= 0xffae00; + + public static final int COLOR_DARK_GRAY = 0x303030; + public static final int COLOR_MEDIUM_GRAY = 0x878787; + public static final int COLOR_LIGHT_GRAY = 0x565656; + + public static final int COLOR_DARK_YELLOW = 0xF7FC26; + public static final int COLOR_LIGHT_YELLOW = 0xD7FF8C; +} diff --git a/home-assistant/src/main/java/com/totalcross/util/Fonts.java b/home-assistant/src/main/java/com/totalcross/util/Fonts.java new file mode 100644 index 0000000..5e92b86 --- /dev/null +++ b/home-assistant/src/main/java/com/totalcross/util/Fonts.java @@ -0,0 +1,6 @@ +package com.totalcross.util; + +public class Fonts { + + public static final String FONT_DEFAULT = "Times New Roman"; +} diff --git a/home-assistant/src/main/java/com/totalcross/util/Images.java b/home-assistant/src/main/java/com/totalcross/util/Images.java new file mode 100644 index 0000000..c3959a7 --- /dev/null +++ b/home-assistant/src/main/java/com/totalcross/util/Images.java @@ -0,0 +1,147 @@ +package com.totalcross.util; + +import totalcross.ui.image.Image; + +import totalcross.ui.dialog.MessageBox; + +public class Images { + + public static Image imgFrozenGray; + public static Image imgFrozenBlue; + public static Image imgCalenderGray; + public static Image imgCalenderGreen; + public static Image imgHotGray; + public static Image imgHotOrange; + public static Image imgOffGray; + public static Image imgOffBlack; + public static Image imgSpotify; + public static Image imgSecurityGreen; + public static Image imgSecurityRed; + public static Image imgEnergy; + public static Image imgSolarPower; + public static Image imgEletricity; + public static Image imgNonFossil; + public static Image imgHomeEnergy; + public static Image imgHarmony; + public static Image imgMap; + public static Image imgLigthBack; + public static Image imgLigthYellow; + public static Image imgCameraDireita; + public static Image imgCameraEsquerda; + + public static void loadFrozen() { + try { + imgFrozenBlue = new Image("images/iconFrozenGray.png"); + // imgFrozenGray = new Image("images/iconFronzenBlule.png"); + + } catch (Exception e) { + MessageBox.showException(e, true); + } + } + + public static void loadCalender() { + try { + imgCalenderGray = new Image("images/iconCalenderGray.png"); + // imgCalenderGreen = new Image("images/iconCalenderGreen.png"); + } catch (Exception e) { + MessageBox.showException(e, true); + } + } + + public static void loadHot() { + try { + imgHotGray = new Image("images/iconHotGray.png"); + // imgHotOrange = new Image("images/iconHotOrange.png"); + } catch (Exception e) { + MessageBox.showException(e, true); + } + } + + public static void loadOff() { + try { + // imgOffBlack = new Image("images/iconOffBlack.png"); + imgOffGray = new Image("images/iconOffGray.png"); + } catch (Exception e) { + MessageBox.showException(e, true); + } + } + + public static void loadSpotify() { + try { + imgSpotify = new Image("images/spotify.png"); + } catch (Exception e) { + MessageBox.showException(e, true); + } + } + + public static void loadSecurity() { + try { + imgSecurityGreen = new Image("images/iconSecurityGreen.png"); + imgSecurityRed = new Image("images/iconSecurityRed.png"); + } catch (Exception e) { + MessageBox.showException(e, true); + } + } + + public static void loadTemperatureStudy() { + try { + imgEnergy = new Image("images/iconPowerCharge.png"); + } catch (Exception e) { + MessageBox.showException(e, true); + } + } + + public static void loadMap(){ + try { + imgMap = new Image("images/mapa.png"); + imgLigthBack = new Image("images/lampBlack.png"); + imgLigthYellow = new Image("images/lampYellow.png"); + imgCameraDireita = new Image("images/cameraDireita.png"); + imgCameraEsquerda = new Image("images/cameraEsquerda.png"); + + } catch (Exception e) { + MessageBox.showException(e, true); + } + } + + public static void loadSolarPower() { + try { + imgSolarPower = new Image("images/SolarPower.png"); + } catch (Exception e) { + MessageBox.showException(e, true); + } + } + + public static void loadEletricity() { + try { + imgEletricity = new Image("images/Eletricity.png"); + } catch (Exception e) { + MessageBox.showException(e, true); + } + } + + public static void loadNonFossil() { + try { + imgNonFossil = new Image("images/Non-fossil.png"); + } catch (Exception e) { + MessageBox.showException(e, true); + } + } + + public static void loadHomeEnergy() { + try { + imgHomeEnergy = new Image("images/homeEnergy.png"); + } catch (Exception e) { + MessageBox.showException(e, true); + } + } + + public static void loadHarmony() { + try { + imgHarmony = new Image("images/Harmony.png"); + imgHarmony.scaledBy(1, 1); + } catch (Exception e) { + MessageBox.showException(e, true); + } + } +} diff --git a/home-assistant/src/main/resources/images/Eletricity.png b/home-assistant/src/main/resources/images/Eletricity.png new file mode 100644 index 0000000..6a35f73 Binary files /dev/null and b/home-assistant/src/main/resources/images/Eletricity.png differ diff --git a/home-assistant/src/main/resources/images/Grid.png b/home-assistant/src/main/resources/images/Grid.png new file mode 100644 index 0000000..39b305f Binary files /dev/null and b/home-assistant/src/main/resources/images/Grid.png differ diff --git a/home-assistant/src/main/resources/images/Harmony.png b/home-assistant/src/main/resources/images/Harmony.png new file mode 100644 index 0000000..58e9a24 Binary files /dev/null and b/home-assistant/src/main/resources/images/Harmony.png differ diff --git a/home-assistant/src/main/resources/images/Home.png b/home-assistant/src/main/resources/images/Home.png new file mode 100644 index 0000000..3aa5553 Binary files /dev/null and b/home-assistant/src/main/resources/images/Home.png differ diff --git a/home-assistant/src/main/resources/images/Non-fossil.png b/home-assistant/src/main/resources/images/Non-fossil.png new file mode 100644 index 0000000..a593157 Binary files /dev/null and b/home-assistant/src/main/resources/images/Non-fossil.png differ diff --git a/home-assistant/src/main/resources/images/Solar.png b/home-assistant/src/main/resources/images/Solar.png new file mode 100644 index 0000000..09d1134 Binary files /dev/null and b/home-assistant/src/main/resources/images/Solar.png differ diff --git a/home-assistant/src/main/resources/images/SolarPower.png b/home-assistant/src/main/resources/images/SolarPower.png new file mode 100644 index 0000000..8390cc1 Binary files /dev/null and b/home-assistant/src/main/resources/images/SolarPower.png differ diff --git a/home-assistant/src/main/resources/images/cameraDireita.png b/home-assistant/src/main/resources/images/cameraDireita.png new file mode 100644 index 0000000..cf02c90 Binary files /dev/null and b/home-assistant/src/main/resources/images/cameraDireita.png differ diff --git a/home-assistant/src/main/resources/images/cameraEsquerda.png b/home-assistant/src/main/resources/images/cameraEsquerda.png new file mode 100644 index 0000000..805a0c0 Binary files /dev/null and b/home-assistant/src/main/resources/images/cameraEsquerda.png differ diff --git a/home-assistant/src/main/resources/images/homeEnergy.png b/home-assistant/src/main/resources/images/homeEnergy.png new file mode 100644 index 0000000..8de86ae Binary files /dev/null and b/home-assistant/src/main/resources/images/homeEnergy.png differ diff --git a/home-assistant/src/main/resources/images/iconCalenderGray.png b/home-assistant/src/main/resources/images/iconCalenderGray.png new file mode 100644 index 0000000..472ec78 Binary files /dev/null and b/home-assistant/src/main/resources/images/iconCalenderGray.png differ diff --git a/home-assistant/src/main/resources/images/iconCalenderGreen.png b/home-assistant/src/main/resources/images/iconCalenderGreen.png new file mode 100644 index 0000000..1c8c7cb Binary files /dev/null and b/home-assistant/src/main/resources/images/iconCalenderGreen.png differ diff --git a/home-assistant/src/main/resources/images/iconFrozenBlue.png b/home-assistant/src/main/resources/images/iconFrozenBlue.png new file mode 100644 index 0000000..e3eb957 Binary files /dev/null and b/home-assistant/src/main/resources/images/iconFrozenBlue.png differ diff --git a/home-assistant/src/main/resources/images/iconFrozenGray.png b/home-assistant/src/main/resources/images/iconFrozenGray.png new file mode 100644 index 0000000..72d7e61 Binary files /dev/null and b/home-assistant/src/main/resources/images/iconFrozenGray.png differ diff --git a/home-assistant/src/main/resources/images/iconHotGray.png b/home-assistant/src/main/resources/images/iconHotGray.png new file mode 100644 index 0000000..714bc24 Binary files /dev/null and b/home-assistant/src/main/resources/images/iconHotGray.png differ diff --git a/home-assistant/src/main/resources/images/iconHotOrange.png b/home-assistant/src/main/resources/images/iconHotOrange.png new file mode 100644 index 0000000..500ad6f Binary files /dev/null and b/home-assistant/src/main/resources/images/iconHotOrange.png differ diff --git a/home-assistant/src/main/resources/images/iconOffBlack.png b/home-assistant/src/main/resources/images/iconOffBlack.png new file mode 100644 index 0000000..febd972 Binary files /dev/null and b/home-assistant/src/main/resources/images/iconOffBlack.png differ diff --git a/home-assistant/src/main/resources/images/iconOffGray.png b/home-assistant/src/main/resources/images/iconOffGray.png new file mode 100644 index 0000000..cf2f1d8 Binary files /dev/null and b/home-assistant/src/main/resources/images/iconOffGray.png differ diff --git a/home-assistant/src/main/resources/images/iconPowerCharge.png b/home-assistant/src/main/resources/images/iconPowerCharge.png new file mode 100644 index 0000000..5eecd31 Binary files /dev/null and b/home-assistant/src/main/resources/images/iconPowerCharge.png differ diff --git a/home-assistant/src/main/resources/images/iconSecurityGreen.png b/home-assistant/src/main/resources/images/iconSecurityGreen.png new file mode 100644 index 0000000..a6def90 Binary files /dev/null and b/home-assistant/src/main/resources/images/iconSecurityGreen.png differ diff --git a/home-assistant/src/main/resources/images/iconSecurityRed.png b/home-assistant/src/main/resources/images/iconSecurityRed.png new file mode 100644 index 0000000..001cba1 Binary files /dev/null and b/home-assistant/src/main/resources/images/iconSecurityRed.png differ diff --git a/home-assistant/src/main/resources/images/imgNFossil.png b/home-assistant/src/main/resources/images/imgNFossil.png new file mode 100644 index 0000000..5770f81 Binary files /dev/null and b/home-assistant/src/main/resources/images/imgNFossil.png differ diff --git a/home-assistant/src/main/resources/images/lampBlack.png b/home-assistant/src/main/resources/images/lampBlack.png new file mode 100644 index 0000000..07ab499 Binary files /dev/null and b/home-assistant/src/main/resources/images/lampBlack.png differ diff --git a/home-assistant/src/main/resources/images/lampYellow.png b/home-assistant/src/main/resources/images/lampYellow.png new file mode 100644 index 0000000..b7ba0e7 Binary files /dev/null and b/home-assistant/src/main/resources/images/lampYellow.png differ diff --git a/home-assistant/src/main/resources/images/mapa.png b/home-assistant/src/main/resources/images/mapa.png new file mode 100644 index 0000000..d00ae74 Binary files /dev/null and b/home-assistant/src/main/resources/images/mapa.png differ diff --git a/home-assistant/src/main/resources/images/spotify.png b/home-assistant/src/main/resources/images/spotify.png new file mode 100644 index 0000000..148e23e Binary files /dev/null and b/home-assistant/src/main/resources/images/spotify.png differ