-
Notifications
You must be signed in to change notification settings - Fork 8
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
Fidelesju
wants to merge
1
commit into
main
Choose a base branch
from
home-assistant
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
35
home-assistant/src/main/java/com/totalcross/HomeAssistant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
home-assistant/src/main/java/com/totalcross/RunHomeAssistantApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
125
home-assistant/src/main/java/com/totalcross/containers/ArcSlider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
@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; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add an empty line at the end of the files |
18 changes: 18 additions & 0 deletions
18
home-assistant/src/main/java/com/totalcross/containers/CircleContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicate code