Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating project Home Assistant #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions home-assistant/.gitignore
Original file line number Diff line number Diff line change
@@ -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*
87 changes: 87 additions & 0 deletions home-assistant/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.totalcross</groupId>
<artifactId>Home-Assistant</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Home-Assistant</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<totalcross.activation_key>5443444B5AAEEB90306B00E4</totalcross.activation_key>
</properties>

<dependencies>
<dependency>
<groupId>com.totalcross</groupId>
<artifactId>totalcross-sdk</artifactId>
<version>7.1.0</version>
</dependency>
</dependencies>

<repositories>
<repository>
<id>totalcross-repo</id>
<name>ip-172-31-40-140-releases</name>
<url>https://maven.totalcross.com/artifactory/repo1</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>totalcross-repo</id>
<name>ip-172-31-40-140-releases</name>
<url>https://maven.totalcross.com/artifactory/repo1</url>
</pluginRepository>
</pluginRepositories>

<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>com.totalcross</groupId>
<artifactId>totalcross-maven-plugin</artifactId>
<version>2.0.4</version>
<configuration>
<name>${project.name}</name>
<platforms>
<platform>-android</platform>
<platform>-win32</platform>
</platforms>
<activationKey>${totalcross.activation_key}</activationKey>
<!-- For version 4.4.2 and 5.1.4 or later, Apple certificates are no longer required. -->
<!-- <certificates>${totalcross.applecertificate}</certificates>-->
<!-- <totalcrossHome>~/TotalCross/6.1.0</totalcrossHome>-->
</configuration>
<executions>
<execution>
<id>post-compile</id>
<phase>compile</phase>
<goals>
<goal>retrolambda</goal>
</goals>
</execution>
<execution>
<id>post-package</id>
<phase>package</phase>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
35 changes: 35 additions & 0 deletions home-assistant/src/main/java/com/totalcross/HomeAssistant.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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");
}
}
125 changes: 125 additions & 0 deletions home-assistant/src/main/java/com/totalcross/containers/ArcSlider.java
Original file line number Diff line number Diff line change
@@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate code

}

@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;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add an empty line at the end of the files

Original file line number Diff line number Diff line change
@@ -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);

}

}
Loading