init
@@ -0,0 +1,3 @@
|
||||
/api/Things4Java/jHomeWebAdmin/target/
|
||||
/api/Things4Java/Things.Prototipo/target/
|
||||
/apps/jHomeAutomation/target/
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="br.com.globalcode.jhome.android"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0" >
|
||||
|
||||
<uses-sdk android:minSdkVersion="7" />
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
|
||||
<application
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name" >
|
||||
<activity
|
||||
android:label="@string/app_name"
|
||||
android:name=".SplashScreenActivity"
|
||||
android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen"
|
||||
android:screenOrientation="portrait" >
|
||||
<intent-filter >
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".DeviceControlsActvitity"
|
||||
android:theme="@android:style/Theme.Black.NoTitleBar"
|
||||
android:screenOrientation="portrait" />
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="br.com.globalcode.jhome.android"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0" >
|
||||
|
||||
<uses-sdk android:minSdkVersion="7" />
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
|
||||
<application
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name" >
|
||||
<activity
|
||||
android:label="@string/app_name"
|
||||
android:name=".SplashScreenActivity"
|
||||
android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen"
|
||||
android:screenOrientation="portrait" >
|
||||
<intent-filter >
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".DeviceControlsActvitity"
|
||||
android:theme="@android:style/Theme.Black.NoTitleBar"
|
||||
android:screenOrientation="portrait" />
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -0,0 +1,3 @@
|
||||
# cache for current jar dependecy. DO NOT EDIT.
|
||||
# format is <lastModified> <length> <SHA-1> <path>
|
||||
# Encoding is UTF-8
|
||||
|
Depois Largura: | Altura: | Tamanho: 1.6 KiB |
|
Depois Largura: | Altura: | Tamanho: 1.9 KiB |
|
Depois Largura: | Altura: | Tamanho: 2.0 KiB |
|
Depois Largura: | Altura: | Tamanho: 2.4 KiB |
|
Depois Largura: | Altura: | Tamanho: 2.9 KiB |
|
Depois Largura: | Altura: | Tamanho: 7.7 KiB |
|
Depois Largura: | Altura: | Tamanho: 19 KiB |
|
Depois Largura: | Altura: | Tamanho: 14 KiB |
|
Depois Largura: | Altura: | Tamanho: 765 B |
|
Depois Largura: | Altura: | Tamanho: 830 B |
|
Depois Largura: | Altura: | Tamanho: 1019 B |
|
Depois Largura: | Altura: | Tamanho: 1.2 KiB |
|
Depois Largura: | Altura: | Tamanho: 1.4 KiB |
|
Depois Largura: | Altura: | Tamanho: 2.8 KiB |
|
Depois Largura: | Altura: | Tamanho: 19 KiB |
|
Depois Largura: | Altura: | Tamanho: 14 KiB |
|
Depois Largura: | Altura: | Tamanho: 1.0 KiB |
|
Depois Largura: | Altura: | Tamanho: 1.3 KiB |
|
Depois Largura: | Altura: | Tamanho: 1.4 KiB |
|
Depois Largura: | Altura: | Tamanho: 1.6 KiB |
|
Depois Largura: | Altura: | Tamanho: 1.8 KiB |
|
Depois Largura: | Altura: | Tamanho: 4.2 KiB |
|
Depois Largura: | Altura: | Tamanho: 19 KiB |
|
Depois Largura: | Altura: | Tamanho: 14 KiB |
|
Depois Largura: | Altura: | Tamanho: 11 KiB |
@@ -0,0 +1,6 @@
|
||||
/** Automatically generated file. DO NOT MODIFY */
|
||||
package br.com.globalcode.jhome.android;
|
||||
|
||||
public final class BuildConfig {
|
||||
public final static boolean DEBUG = true;
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/* AUTO-GENERATED FILE. DO NOT MODIFY.
|
||||
*
|
||||
* This class was automatically generated by the
|
||||
* aapt tool from the resource data it found. It
|
||||
* should not be modified by hand.
|
||||
*/
|
||||
|
||||
package br.com.globalcode.jhome.android;
|
||||
|
||||
public final class R {
|
||||
public static final class attr {
|
||||
}
|
||||
public static final class drawable {
|
||||
public static final int ic_btn_add=0x7f020000;
|
||||
public static final int ic_btn_del=0x7f020001;
|
||||
public static final int ic_btn_refresh=0x7f020002;
|
||||
public static final int ic_btn_run=0x7f020003;
|
||||
public static final int ic_btn_settings=0x7f020004;
|
||||
public static final int ic_launcher=0x7f020005;
|
||||
public static final int img_jhome_big=0x7f020006;
|
||||
public static final int img_jhome_small=0x7f020007;
|
||||
}
|
||||
public static final class id {
|
||||
public static final int analog_deviceName=0x7f050000;
|
||||
public static final int analog_deviceValue=0x7f050001;
|
||||
public static final int devices_controlsLayout=0x7f05000d;
|
||||
public static final int devices_refreshButton=0x7f050008;
|
||||
public static final int devices_serverIpTextView=0x7f050006;
|
||||
public static final int devices_settingsButton=0x7f05000a;
|
||||
public static final int digital_deviceNameTextView=0x7f05000f;
|
||||
public static final int digital_deviceToggleButton=0x7f05000e;
|
||||
public static final int imageView1=0x7f050003;
|
||||
public static final int linearLayout1=0x7f050002;
|
||||
public static final int linearLayout2=0x7f050004;
|
||||
public static final int linearLayout3=0x7f050007;
|
||||
public static final int pwm_deviceName=0x7f050010;
|
||||
public static final int pwm_digitalSeekBar=0x7f050011;
|
||||
public static final int scrollView1=0x7f05000c;
|
||||
public static final int textView1=0x7f050005;
|
||||
public static final int textView3=0x7f050009;
|
||||
public static final int textView4=0x7f05000b;
|
||||
}
|
||||
public static final class layout {
|
||||
public static final int device_analog=0x7f030000;
|
||||
public static final int device_controls_layout=0x7f030001;
|
||||
public static final int device_digital=0x7f030002;
|
||||
public static final int device_pwm=0x7f030003;
|
||||
public static final int splash_screen_layout=0x7f030004;
|
||||
}
|
||||
public static final class string {
|
||||
public static final int app_name=0x7f040000;
|
||||
public static final int attetion=0x7f040001;
|
||||
public static final int connection_error=0x7f040003;
|
||||
public static final int devices_automatic_scan_dialog=0x7f04000a;
|
||||
public static final int devices_change_server_ip_title=0x7f04000c;
|
||||
public static final int devices_loading_devices_db=0x7f040007;
|
||||
public static final int devices_no_devices_found_dialog=0x7f040009;
|
||||
public static final int devices_refresh_button=0x7f04000b;
|
||||
public static final int devices_searching_devices=0x7f040008;
|
||||
public static final int devices_server_ip_label=0x7f040006;
|
||||
public static final int devices_settings_button=0x7f040005;
|
||||
public static final int devices_title=0x7f040004;
|
||||
public static final int error=0x7f040002;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<lint>
|
||||
</lint>
|
||||
@@ -0,0 +1,40 @@
|
||||
-optimizationpasses 5
|
||||
-dontusemixedcaseclassnames
|
||||
-dontskipnonpubliclibraryclasses
|
||||
-dontpreverify
|
||||
-verbose
|
||||
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
|
||||
|
||||
-keep public class * extends android.app.Activity
|
||||
-keep public class * extends android.app.Application
|
||||
-keep public class * extends android.app.Service
|
||||
-keep public class * extends android.content.BroadcastReceiver
|
||||
-keep public class * extends android.content.ContentProvider
|
||||
-keep public class * extends android.app.backup.BackupAgentHelper
|
||||
-keep public class * extends android.preference.Preference
|
||||
-keep public class com.android.vending.licensing.ILicensingService
|
||||
|
||||
-keepclasseswithmembernames class * {
|
||||
native <methods>;
|
||||
}
|
||||
|
||||
-keepclasseswithmembers class * {
|
||||
public <init>(android.content.Context, android.util.AttributeSet);
|
||||
}
|
||||
|
||||
-keepclasseswithmembers class * {
|
||||
public <init>(android.content.Context, android.util.AttributeSet, int);
|
||||
}
|
||||
|
||||
-keepclassmembers class * extends android.app.Activity {
|
||||
public void *(android.view.View);
|
||||
}
|
||||
|
||||
-keepclassmembers enum * {
|
||||
public static **[] values();
|
||||
public static ** valueOf(java.lang.String);
|
||||
}
|
||||
|
||||
-keep class * implements android.os.Parcelable {
|
||||
public static final android.os.Parcelable$Creator *;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
# This file is automatically generated by Android Tools.
|
||||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||
#
|
||||
# This file must be checked in Version Control Systems.
|
||||
#
|
||||
# To customize properties used by the Ant build system use,
|
||||
# "ant.properties", and override values to adapt the script to your
|
||||
# project structure.
|
||||
|
||||
# Project target.
|
||||
target=android-10
|
||||
|
Depois Largura: | Altura: | Tamanho: 1.3 KiB |
|
Depois Largura: | Altura: | Tamanho: 2.0 KiB |
|
Depois Largura: | Altura: | Tamanho: 2.2 KiB |
|
Depois Largura: | Altura: | Tamanho: 2.5 KiB |
|
Depois Largura: | Altura: | Tamanho: 3.0 KiB |
|
Depois Largura: | Altura: | Tamanho: 10 KiB |
|
Depois Largura: | Altura: | Tamanho: 20 KiB |
|
Depois Largura: | Altura: | Tamanho: 15 KiB |
|
Depois Largura: | Altura: | Tamanho: 719 B |
|
Depois Largura: | Altura: | Tamanho: 874 B |
|
Depois Largura: | Altura: | Tamanho: 1009 B |
|
Depois Largura: | Altura: | Tamanho: 1.1 KiB |
|
Depois Largura: | Altura: | Tamanho: 1.2 KiB |
|
Depois Largura: | Altura: | Tamanho: 5.5 KiB |
|
Depois Largura: | Altura: | Tamanho: 20 KiB |
|
Depois Largura: | Altura: | Tamanho: 15 KiB |
|
Depois Largura: | Altura: | Tamanho: 960 B |
|
Depois Largura: | Altura: | Tamanho: 1.2 KiB |
|
Depois Largura: | Altura: | Tamanho: 1.4 KiB |
|
Depois Largura: | Altura: | Tamanho: 1.6 KiB |
|
Depois Largura: | Altura: | Tamanho: 1.9 KiB |
|
Depois Largura: | Altura: | Tamanho: 6.9 KiB |
|
Depois Largura: | Altura: | Tamanho: 20 KiB |
|
Depois Largura: | Altura: | Tamanho: 15 KiB |
|
Depois Largura: | Altura: | Tamanho: 14 KiB |
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="10dp" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/analog_deviceName"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Medium Text"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/analog_deviceValue"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Medium Text"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,98 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linearLayout1"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/img_jhome_small" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linearLayout2"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/devices_title"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/devices_serverIpTextView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/devices_server_ip_label"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linearLayout3"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:padding="10dp" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/devices_refreshButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/ic_btn_refresh" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:text="@string/devices_refresh_button"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/devices_settingsButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:background="@drawable/ic_btn_settings" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView4"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:text="@string/devices_settings_button"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ScrollView
|
||||
android:id="@+id/scrollView1"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/devices_controlsLayout"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:padding="10dp" >
|
||||
|
||||
<ToggleButton
|
||||
android:id="@+id/digital_deviceToggleButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:text="ToggleButton" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/digital_deviceNameTextView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:text="Medium Text"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
</RelativeLayout>
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="10dp" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/pwm_deviceName"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Medium Text"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/pwm_digitalSeekBar"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingRight="10dp"
|
||||
android:max="255" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/img_jhome_big" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="app_name">JHome</string>
|
||||
<string name="attetion">Attention!</string>
|
||||
<string name="error">Attention!</string>
|
||||
<string name="connection_error">Connection Error!</string>
|
||||
<string name="devices_title">Devices List</string>
|
||||
<string name="devices_settings_button">Settings</string>
|
||||
<string name="devices_server_ip_label">Server: </string>
|
||||
<string name="devices_loading_devices_db">Loading devices list...</string>
|
||||
<string name="devices_searching_devices">Searching for devices...</string>
|
||||
<string name="devices_no_devices_found_dialog">No devices found!</string>
|
||||
<string name="devices_automatic_scan_dialog">Proceed the automatic scan on the central at </string>
|
||||
<string name="devices_refresh_button">Refresh Devices</string>
|
||||
<string name="devices_change_server_ip_title">New server IP:</string>
|
||||
</resources>
|
||||
@@ -0,0 +1,345 @@
|
||||
package br.com.globalcode.jhome.android;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.ToggleButton;
|
||||
import android.widget.SeekBar.OnSeekBarChangeListener;
|
||||
import br.com.globalcode.jhome.android.bean.Device;
|
||||
import br.com.globalcode.jhome.android.bean.DeviceType;
|
||||
import br.com.globalcode.jhome.android.controller.DeviceController;
|
||||
import br.com.globalcode.jhome.android.model.DeviceModel;
|
||||
import br.com.globalcode.jhome.android.ws.CentralWS;
|
||||
import br.com.globalcode.jhome.android.ws.DeviceWS;
|
||||
|
||||
public class DeviceControlsActvitity extends Activity implements android.view.View.OnClickListener, OnSeekBarChangeListener {
|
||||
|
||||
public static final String DEFAULT_IP_SERVER = "192.168.1.3";
|
||||
|
||||
public static final String PREF_SERVER_ADDRESS = "server";
|
||||
public static final String PREF_DEVICE_NAME = "device_name";
|
||||
|
||||
private static final int DIALOG_SEARCH_DEVICES = 1;
|
||||
private static final int DIALOG_CHANGE_SERVER_IP = 2;
|
||||
private static final int DIALOG_CONNECTION_ERROR = 3;
|
||||
|
||||
private boolean firstTime;
|
||||
private ProgressDialog progressDialog;
|
||||
private String serverAddress;
|
||||
private String deviceName;
|
||||
private ArrayList<Device> devices;
|
||||
private EditText ipEditText;
|
||||
private Hashtable<View, Device> deviceControls;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.device_controls_layout);
|
||||
|
||||
findViewById(R.id.devices_settingsButton).setOnClickListener(new View.OnClickListener() {
|
||||
@SuppressWarnings("deprecation")
|
||||
public void onClick(View v) {
|
||||
showDialog(DIALOG_CHANGE_SERVER_IP);
|
||||
}
|
||||
});
|
||||
|
||||
findViewById(R.id.devices_refreshButton).setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
public void onClick(View v) {
|
||||
searchDevices();
|
||||
}
|
||||
});
|
||||
|
||||
loadPreferences();
|
||||
// refreshServerTextView();
|
||||
firstTime = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean hasFocus) {
|
||||
super.onWindowFocusChanged(hasFocus);
|
||||
|
||||
if (hasFocus && this.devices == null && firstTime) {
|
||||
refreshServerTextView();
|
||||
firstTime = false;
|
||||
loadDeviceList();
|
||||
if (this.devices.size() == 0) {
|
||||
showDialog(DIALOG_SEARCH_DEVICES);
|
||||
} else {
|
||||
addDeviceControls();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadPreferences() {
|
||||
SharedPreferences prefs = PreferenceManager
|
||||
.getDefaultSharedPreferences(this);
|
||||
this.serverAddress = prefs.getString(PREF_SERVER_ADDRESS,
|
||||
DEFAULT_IP_SERVER);
|
||||
this.deviceName = prefs.getString(PREF_DEVICE_NAME, "");
|
||||
}
|
||||
|
||||
private void saveNewIpAddress() {
|
||||
this.serverAddress = this.ipEditText.getText().toString();
|
||||
SharedPreferences.Editor editor = PreferenceManager
|
||||
.getDefaultSharedPreferences(this).edit();
|
||||
editor.putString(PREF_SERVER_ADDRESS, this.serverAddress);
|
||||
editor.commit();
|
||||
refreshServerTextView();
|
||||
this.removeDeviceControls();
|
||||
DeviceModel.clearDevices(this);
|
||||
removeDialog(DIALOG_SEARCH_DEVICES);
|
||||
showDialog(DIALOG_SEARCH_DEVICES);
|
||||
}
|
||||
|
||||
private void refreshServerTextView() {
|
||||
((TextView) findViewById(R.id.devices_serverIpTextView))
|
||||
.setText(getString(R.string.devices_server_ip_label)
|
||||
+ " " + this.serverAddress);
|
||||
}
|
||||
|
||||
private void loadDeviceList() {
|
||||
ProgressDialog progressDialog = ProgressDialog.show(this, null,
|
||||
getString(R.string.devices_loading_devices_db));
|
||||
this.devices = DeviceModel.getDeviceList(this);
|
||||
progressDialog.cancel();
|
||||
}
|
||||
|
||||
private void searchDevices() {
|
||||
new AsyncTask<String, Integer, String>() {
|
||||
|
||||
protected void onPreExecute() {
|
||||
progressDialog = ProgressDialog.show(DeviceControlsActvitity.this, null,
|
||||
getString(R.string.devices_searching_devices));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String doInBackground(String... params) {
|
||||
String result = CentralWS.discovery(params[0],
|
||||
Integer.parseInt(params[1]));
|
||||
return result;
|
||||
}
|
||||
|
||||
protected void onPostExecute(String result) {
|
||||
progressDialog.dismiss();
|
||||
parseDeviceDiscovery(result);
|
||||
}
|
||||
}.execute(this.serverAddress, Integer.toString(8080));
|
||||
}
|
||||
|
||||
private void parseDeviceDiscovery(String result) {
|
||||
if (result == null) {
|
||||
showDialog(DIALOG_CONNECTION_ERROR);
|
||||
return;
|
||||
}
|
||||
this.devices = DeviceController.parseDeviceDiscovery(result);
|
||||
DeviceModel.clearDevices(this);
|
||||
|
||||
for (Device d : this.devices) {
|
||||
long rowid = DeviceModel.insertDevice(this, d.getDeviceName(),
|
||||
d.getDeviceAddress(), d.getDeviceType(), d.getDevicePort(),
|
||||
d.getValue());
|
||||
d.setId(rowid);
|
||||
}
|
||||
|
||||
addDeviceControls();
|
||||
}
|
||||
|
||||
private void addDeviceControls() {
|
||||
removeDeviceControls();
|
||||
this.deviceControls = new Hashtable<View, Device>();
|
||||
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
|
||||
|
||||
for (Device d : this.devices) {
|
||||
View v = null;
|
||||
if (d.getDeviceType().equals(DeviceType.DIGITAL) || d.getDeviceType().equals(DeviceType.RELAY) ||
|
||||
d.getDeviceType().equals(DeviceType.LED)) {
|
||||
v = inflater.inflate(R.layout.device_digital, null);
|
||||
((TextView)v.findViewById(R.id.digital_deviceNameTextView)).setText(d.getDeviceName());
|
||||
|
||||
ToggleButton t = (ToggleButton) v.findViewById(R.id.digital_deviceToggleButton);
|
||||
if (d.getValue() == 1) {
|
||||
t.setChecked(true);
|
||||
}
|
||||
t.setOnClickListener(this);
|
||||
this.deviceControls.put(t, d);
|
||||
} else if (d.getDeviceType().equals(DeviceType.PWM) || d.getDeviceType().equals(DeviceType.LEDPWM) ||
|
||||
d.getDeviceType().equals(DeviceType.RGB)) {
|
||||
v = inflater.inflate(R.layout.device_pwm, null);
|
||||
((TextView)v.findViewById(R.id.pwm_deviceName)).setText(d.getDeviceName());
|
||||
|
||||
SeekBar s = (SeekBar)v.findViewById(R.id.pwm_digitalSeekBar);
|
||||
s.setProgress(d.getValue());
|
||||
s.setOnSeekBarChangeListener(this);
|
||||
this.deviceControls.put(s, d);
|
||||
} else if (d.getDeviceType().equals(DeviceType.ANALOG) || d.getDeviceType().equals(DeviceType.TEMP) ||
|
||||
d.getDeviceType().equals(DeviceType.LIGHT) || d.getDeviceType().equals(DeviceType.DISTANCE_EZ1) ||
|
||||
d.getDeviceType().equals(DeviceType.POTENCIOMETER)) {
|
||||
v = inflater.inflate(R.layout.device_analog, null);
|
||||
((TextView)v.findViewById(R.id.analog_deviceName)).setText(d.getDeviceName());
|
||||
((TextView)v.findViewById(R.id.analog_deviceValue)).setText(Integer.toString(d.getValue()));
|
||||
v.setOnClickListener(this);
|
||||
this.deviceControls.put(v, d);
|
||||
}
|
||||
|
||||
if (v != null) {
|
||||
((LinearLayout)findViewById(R.id.devices_controlsLayout)).addView(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void removeDeviceControls() {
|
||||
((LinearLayout)findViewById(R.id.devices_controlsLayout)).removeAllViews();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Dialog onCreateDialog(int id) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
|
||||
if (id == DIALOG_SEARCH_DEVICES) {
|
||||
builder.setTitle(
|
||||
getString(R.string.devices_no_devices_found_dialog))
|
||||
.setMessage(
|
||||
getString(R.string.devices_automatic_scan_dialog) + " "
|
||||
+ this.serverAddress + " ?")
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.setPositiveButton("Scan",
|
||||
new DialogInterface.OnClickListener() {
|
||||
|
||||
public void onClick(DialogInterface dialog,
|
||||
int which) {
|
||||
searchDevices();
|
||||
}
|
||||
})
|
||||
.setNegativeButton("Cancel", null)
|
||||
.setNeutralButton("Change Server",
|
||||
new DialogInterface.OnClickListener() {
|
||||
|
||||
public void onClick(DialogInterface dialog,
|
||||
int which) {
|
||||
dialog.dismiss();
|
||||
showDialog(DIALOG_CHANGE_SERVER_IP);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
} else if (id == DIALOG_CHANGE_SERVER_IP) {
|
||||
if (this.ipEditText == null) {
|
||||
ipEditText = new EditText(this);
|
||||
}
|
||||
ipEditText.setText(this.serverAddress);
|
||||
|
||||
builder.setTitle(getString(R.string.devices_change_server_ip_title))
|
||||
.setView(ipEditText)
|
||||
.setPositiveButton("Save", new OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (ipEditText.getText().toString() != null &&
|
||||
ipEditText.getText().toString().equals(serverAddress)) {
|
||||
dialog.dismiss();
|
||||
} else if (ipEditText.getText().length() > 0) {
|
||||
saveNewIpAddress();
|
||||
} else {
|
||||
dialog.dismiss();
|
||||
showDialog(DIALOG_CHANGE_SERVER_IP);
|
||||
}
|
||||
}
|
||||
})
|
||||
.setNegativeButton("Cancel", null);
|
||||
} else if (id == DIALOG_CONNECTION_ERROR) {
|
||||
builder.setTitle(R.string.error)
|
||||
.setMessage(getString(R.string.connection_error))
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.setNeutralButton("OK", null);
|
||||
}
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
// Device d = this.deviceControls.get(seekBar);
|
||||
// sendCommandToDevice(d.getDeviceName(), seekBar.getProgress());
|
||||
}
|
||||
|
||||
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
|
||||
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
Device d = this.deviceControls.get(seekBar);
|
||||
sendCommandToDevice(d.getDeviceName(), seekBar.getProgress());
|
||||
}
|
||||
|
||||
|
||||
public void onClick(View view) {
|
||||
Device d = this.deviceControls.get(view);
|
||||
if (d.getDeviceType().equals(DeviceType.ANALOG) || d.getDeviceType().equals(DeviceType.TEMP) ||
|
||||
d.getDeviceType().equals(DeviceType.LIGHT) || d.getDeviceType().equals(DeviceType.DISTANCE_EZ1) ||
|
||||
d.getDeviceType().equals(DeviceType.POTENCIOMETER)) {
|
||||
refreshDeviceValue(view);
|
||||
|
||||
} else {
|
||||
ToggleButton t = (ToggleButton) view;
|
||||
int value = t.isChecked() ? 1 : 0;
|
||||
sendCommandToDevice(d.getDeviceName(), value);
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshDeviceValue(View view) {
|
||||
new AsyncTask<View, Integer, String>() {
|
||||
|
||||
private View view;
|
||||
|
||||
@Override
|
||||
protected String doInBackground(View... params) {
|
||||
this.view = params[0];
|
||||
Device d = deviceControls.get(params[0]);
|
||||
String result = DeviceWS.read(serverAddress, 8080, d.getDeviceName());
|
||||
return result;
|
||||
}
|
||||
|
||||
protected void onPostExecute(String result) {
|
||||
if (result != null) {
|
||||
Device d = deviceControls.get(view);
|
||||
if ( d.getDeviceType().equalsIgnoreCase(DeviceType.TEMP)) {
|
||||
result = Float.toString((Float.parseFloat(result) * (float)0.00488));
|
||||
}
|
||||
|
||||
((TextView)view.findViewById(R.id.analog_deviceValue)).setText(result);
|
||||
}
|
||||
}
|
||||
|
||||
}.execute(view);
|
||||
}
|
||||
|
||||
private void sendCommandToDevice(String deviceName, int value) {
|
||||
new AsyncTask<String, Integer, String>() {
|
||||
|
||||
@Override
|
||||
protected String doInBackground(String... params) {
|
||||
String result = DeviceWS.send(serverAddress, 8080, params[0], params[1]);
|
||||
return result;
|
||||
}
|
||||
|
||||
}.execute(deviceName, Integer.toString(value));
|
||||
|
||||
Log.d("jHome", "Device: " + deviceName + " - Command: "+value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package br.com.globalcode.jhome.android;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
|
||||
public class SplashScreenActivity extends Activity {
|
||||
|
||||
Class<?> activityClass;
|
||||
Class<?>[] paramTypes = { Integer.TYPE, Integer.TYPE };
|
||||
|
||||
Method overrideAnimation = null;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.splash_screen_layout);
|
||||
|
||||
try {
|
||||
activityClass = Class.forName("android.app.Activity");
|
||||
overrideAnimation = activityClass.getDeclaredMethod("overridePendingTransition",
|
||||
paramTypes);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Handler handler = new Handler();
|
||||
handler.postDelayed(new Runnable() {
|
||||
public void run() {
|
||||
Intent i = new Intent(SplashScreenActivity.this,
|
||||
DeviceControlsActvitity.class);
|
||||
startActivity(i);
|
||||
finish();
|
||||
if (overrideAnimation != null) {
|
||||
try {
|
||||
overrideAnimation.invoke(SplashScreenActivity.this, android.R.anim.fade_in,
|
||||
android.R.anim.fade_out);
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 2000);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package br.com.globalcode.jhome.android.bean;
|
||||
|
||||
public class Device {
|
||||
|
||||
private long id;
|
||||
private String deviceName;
|
||||
private String deviceAddress;
|
||||
private String deviceType;
|
||||
private int devicePort;
|
||||
private int value;
|
||||
|
||||
public Device() {
|
||||
}
|
||||
|
||||
public Device(int id, String deviceName, String deviceAddress,
|
||||
String deviceType, int devicePort, int value) {
|
||||
this.id = id;
|
||||
this.deviceName = deviceName;
|
||||
this.deviceAddress = deviceAddress;
|
||||
this.deviceType = deviceType;
|
||||
this.devicePort = devicePort;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long rowid) {
|
||||
this.id = rowid;
|
||||
}
|
||||
|
||||
public String getDeviceName() {
|
||||
return deviceName;
|
||||
}
|
||||
|
||||
public void setDeviceName(String deviceName) {
|
||||
this.deviceName = deviceName;
|
||||
}
|
||||
|
||||
public String getDeviceAddress() {
|
||||
return deviceAddress;
|
||||
}
|
||||
|
||||
public void setDeviceAddress(String deviceAddress) {
|
||||
this.deviceAddress = deviceAddress;
|
||||
}
|
||||
|
||||
public String getDeviceType() {
|
||||
return deviceType;
|
||||
}
|
||||
|
||||
public void setDeviceType(String deviceType) {
|
||||
this.deviceType = deviceType;
|
||||
}
|
||||
|
||||
public int getDevicePort() {
|
||||
return devicePort;
|
||||
}
|
||||
|
||||
public void setDevicePort(int devicePort) {
|
||||
this.devicePort = devicePort;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||