├── .gitignore
├── app-release.apk
├── src
├── main
│ ├── assets
│ │ ├── wip.gif
│ │ └── wip.html
│ ├── ic_launcher-web.png
│ ├── res
│ │ ├── drawable
│ │ │ ├── mgd.gif
│ │ │ ├── soil.jpg
│ │ │ ├── wip.gif
│ │ │ ├── level.jpg
│ │ │ ├── mappic.jpg
│ │ │ ├── water.jpg
│ │ │ ├── mappicon.jpg
│ │ │ ├── moisture.jpg
│ │ │ ├── mwelcome.gif
│ │ │ ├── smarthome.jpg
│ │ │ ├── hbackground.jpg
│ │ │ ├── smarthome2.jpg
│ │ │ ├── temperature.jpg
│ │ │ └── finalhumidity.jpg
│ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-hdpi
│ │ │ ├── ic_info_black_24dp.png
│ │ │ ├── ic_sync_black_24dp.png
│ │ │ └── ic_notifications_black_24dp.png
│ │ ├── drawable-mdpi
│ │ │ ├── ic_info_black_24dp.png
│ │ │ ├── ic_sync_black_24dp.png
│ │ │ └── ic_notifications_black_24dp.png
│ │ ├── drawable-xhdpi
│ │ │ ├── ic_info_black_24dp.png
│ │ │ ├── ic_sync_black_24dp.png
│ │ │ └── ic_notifications_black_24dp.png
│ │ ├── drawable-xxhdpi
│ │ │ ├── ic_info_black_24dp.png
│ │ │ ├── ic_sync_black_24dp.png
│ │ │ └── ic_notifications_black_24dp.png
│ │ ├── drawable-xxxhdpi
│ │ │ ├── ic_info_black_24dp.png
│ │ │ ├── ic_sync_black_24dp.png
│ │ │ └── ic_notifications_black_24dp.png
│ │ ├── layout
│ │ │ ├── content_experiment2.xml
│ │ │ ├── content_client.xml
│ │ │ ├── content_calender_test.xml
│ │ │ ├── content_animation_gif.xml
│ │ │ ├── fragment_two.xml
│ │ │ ├── fragment_three.xml
│ │ │ ├── fragment_one.xml
│ │ │ ├── content_todo.xml
│ │ │ ├── item_todo.xml
│ │ │ ├── activity_main.xml
│ │ │ ├── activity_todo.xml
│ │ │ ├── activity_client.xml
│ │ │ ├── activity_ip.xml
│ │ │ ├── activity_pid.xml
│ │ │ ├── activity_tab.xml
│ │ │ ├── activity_level.xml
│ │ │ ├── activity_main2.xml
│ │ │ ├── activity_main3.xml
│ │ │ ├── activity_main4.xml
│ │ │ ├── activity_main22.xml
│ │ │ ├── activity_experiment.xml
│ │ │ ├── activity_experiment2.xml
│ │ │ ├── activity_humidity.xml
│ │ │ ├── activity_moisture.xml
│ │ │ ├── activity_voice_help.xml
│ │ │ ├── activity_animation_gif.xml
│ │ │ ├── activity_calender_test.xml
│ │ │ ├── activity_new_socket.xml
│ │ │ ├── activity_parameter.xml
│ │ │ ├── activity_raspberry_pi.xml
│ │ │ ├── content_new_socket.xml
│ │ │ ├── activity_temperature.xml
│ │ │ ├── activity_outputcontrol.xml
│ │ │ ├── content_tab.xml
│ │ │ ├── content_moisture.xml
│ │ │ ├── content_humidity.xml
│ │ │ ├── content_level.xml
│ │ │ ├── content_pid.xml
│ │ │ ├── content_main3.xml
│ │ │ ├── activity_fan_speed.xml
│ │ │ ├── activity_brightness_activity.xml
│ │ │ ├── content_main22.xml
│ │ │ ├── content_experiment.xml
│ │ │ ├── content_ip.xml
│ │ │ ├── content_temperature.xml
│ │ │ ├── content_parameter.xml
│ │ │ ├── content_main.xml
│ │ │ ├── content_outputcontrol.xml
│ │ │ ├── content_main4.xml
│ │ │ └── content_raspberry_pi.xml
│ │ ├── values
│ │ │ ├── colors.xml
│ │ │ ├── dimens.xml
│ │ │ ├── attrs.xml
│ │ │ └── styles.xml
│ │ ├── values-v21
│ │ │ └── styles.xml
│ │ ├── menu
│ │ │ ├── menu_main.xml
│ │ │ ├── menu_tab.xml
│ │ │ └── menu_voice_help.xml
│ │ ├── values-w820dp
│ │ │ └── dimens.xml
│ │ ├── drawable-v21
│ │ │ ├── ic_info_black_24dp.xml
│ │ │ ├── ic_notifications_black_24dp.xml
│ │ │ └── ic_sync_black_24dp.xml
│ │ └── xml
│ │ │ ├── pref_headers.xml
│ │ │ ├── pref_data_sync.xml
│ │ │ ├── pref_notification.xml
│ │ │ └── pref_general.xml
│ ├── java
│ │ └── com
│ │ │ └── mithu
│ │ │ └── mithunmistry
│ │ │ └── mithun
│ │ │ ├── Point.java
│ │ │ ├── OneFragment.java
│ │ │ ├── TwoFragment.java
│ │ │ ├── ThreeFragment.java
│ │ │ ├── animationGif.java
│ │ │ ├── PagerAdapter.java
│ │ │ ├── todo.java
│ │ │ ├── calenderTest.java
│ │ │ ├── VoiceHelp.java
│ │ │ ├── Main4Activity.java
│ │ │ ├── ParameterActivity.java
│ │ │ ├── LineGraph.java
│ │ │ ├── NewSocketActivity.java
│ │ │ ├── MockData.java
│ │ │ ├── MainActivity.java
│ │ │ ├── PidActivity.java
│ │ │ ├── MoistureActivity.java
│ │ │ ├── LevelActivity.java
│ │ │ ├── TabActivity.java
│ │ │ ├── HumidityActivity.java
│ │ │ ├── Main22Activity.java
│ │ │ ├── experiment2.java
│ │ │ ├── TemperatureActivity.java
│ │ │ └── brightness_activity.java
│ └── AndroidManifest.xml
├── test
│ └── java
│ │ └── com
│ │ └── example
│ │ └── mithunmistry
│ │ └── mithun
│ │ └── ExampleUnitTest.java
└── androidTest
│ └── java
│ └── com
│ └── mithu
│ └── mithunmistry
│ └── mithun
│ └── ApplicationTest.java
├── libs
└── achartengine-1.0.0.jar
├── proguard-rules.pro
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app-release.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/app-release.apk
--------------------------------------------------------------------------------
/src/main/assets/wip.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/assets/wip.gif
--------------------------------------------------------------------------------
/libs/achartengine-1.0.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/libs/achartengine-1.0.0.jar
--------------------------------------------------------------------------------
/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/src/main/res/drawable/mgd.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/drawable/mgd.gif
--------------------------------------------------------------------------------
/src/main/res/drawable/soil.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/drawable/soil.jpg
--------------------------------------------------------------------------------
/src/main/res/drawable/wip.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/drawable/wip.gif
--------------------------------------------------------------------------------
/src/main/res/drawable/level.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/drawable/level.jpg
--------------------------------------------------------------------------------
/src/main/res/drawable/mappic.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/drawable/mappic.jpg
--------------------------------------------------------------------------------
/src/main/res/drawable/water.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/drawable/water.jpg
--------------------------------------------------------------------------------
/src/main/res/drawable/mappicon.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/drawable/mappicon.jpg
--------------------------------------------------------------------------------
/src/main/res/drawable/moisture.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/drawable/moisture.jpg
--------------------------------------------------------------------------------
/src/main/res/drawable/mwelcome.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/drawable/mwelcome.gif
--------------------------------------------------------------------------------
/src/main/res/drawable/smarthome.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/drawable/smarthome.jpg
--------------------------------------------------------------------------------
/src/main/res/drawable/hbackground.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/drawable/hbackground.jpg
--------------------------------------------------------------------------------
/src/main/res/drawable/smarthome2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/drawable/smarthome2.jpg
--------------------------------------------------------------------------------
/src/main/res/drawable/temperature.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/drawable/temperature.jpg
--------------------------------------------------------------------------------
/src/main/res/drawable/finalhumidity.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/drawable/finalhumidity.jpg
--------------------------------------------------------------------------------
/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/main/assets/wip.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/main/res/drawable-hdpi/ic_info_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/drawable-hdpi/ic_info_black_24dp.png
--------------------------------------------------------------------------------
/src/main/res/drawable-hdpi/ic_sync_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/drawable-hdpi/ic_sync_black_24dp.png
--------------------------------------------------------------------------------
/src/main/res/drawable-mdpi/ic_info_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/drawable-mdpi/ic_info_black_24dp.png
--------------------------------------------------------------------------------
/src/main/res/drawable-mdpi/ic_sync_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/drawable-mdpi/ic_sync_black_24dp.png
--------------------------------------------------------------------------------
/src/main/res/drawable-xhdpi/ic_info_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/drawable-xhdpi/ic_info_black_24dp.png
--------------------------------------------------------------------------------
/src/main/res/drawable-xhdpi/ic_sync_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/drawable-xhdpi/ic_sync_black_24dp.png
--------------------------------------------------------------------------------
/src/main/res/drawable-xxhdpi/ic_info_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/drawable-xxhdpi/ic_info_black_24dp.png
--------------------------------------------------------------------------------
/src/main/res/drawable-xxhdpi/ic_sync_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/drawable-xxhdpi/ic_sync_black_24dp.png
--------------------------------------------------------------------------------
/src/main/res/drawable-xxxhdpi/ic_info_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/drawable-xxxhdpi/ic_info_black_24dp.png
--------------------------------------------------------------------------------
/src/main/res/drawable-xxxhdpi/ic_sync_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/drawable-xxxhdpi/ic_sync_black_24dp.png
--------------------------------------------------------------------------------
/src/main/res/drawable-hdpi/ic_notifications_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/drawable-hdpi/ic_notifications_black_24dp.png
--------------------------------------------------------------------------------
/src/main/res/drawable-mdpi/ic_notifications_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/drawable-mdpi/ic_notifications_black_24dp.png
--------------------------------------------------------------------------------
/src/main/res/drawable-xhdpi/ic_notifications_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/drawable-xhdpi/ic_notifications_black_24dp.png
--------------------------------------------------------------------------------
/src/main/res/drawable-xxhdpi/ic_notifications_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/drawable-xxhdpi/ic_notifications_black_24dp.png
--------------------------------------------------------------------------------
/src/main/res/drawable-xxxhdpi/ic_notifications_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mithunjmistry/IOT-Raspberry-Pi-Android-App/HEAD/src/main/res/drawable-xxxhdpi/ic_notifications_black_24dp.png
--------------------------------------------------------------------------------
/src/main/res/layout/content_experiment2.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
--------------------------------------------------------------------------------
/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 | #66000000
8 |
9 |
--------------------------------------------------------------------------------
/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 | >
2 |
8 |
9 |
--------------------------------------------------------------------------------
/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/src/main/res/menu/menu_tab.xml:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/src/main/res/menu/menu_voice_help.xml:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/src/test/java/com/example/mithunmistry/mithun/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.mithu.mithunmistry.mithun;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 16dp
6 | 180dp
7 | 16dp
8 | 8dp
9 |
10 |
--------------------------------------------------------------------------------
/src/androidTest/java/com/mithu/mithunmistry/mithun/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.mithu.mithunmistry.mithun;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/src/main/res/drawable-v21/ic_info_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/src/main/java/com/mithu/mithunmistry/mithun/Point.java:
--------------------------------------------------------------------------------
1 | package com.mithu.mithunmistry.mithun;
2 |
3 | /**
4 | * Created by Mithun Mistry on 27-04-2016.
5 | */
6 | public class Point {
7 |
8 | private int x;
9 | private int y;
10 |
11 | public Point( int x, int y)
12 | {
13 | this.x = x;
14 | this.y = y;
15 | }
16 |
17 | public int getX() {
18 | return x;
19 | }
20 |
21 | public int getY() {
22 | return y;
23 | }
24 |
25 | }
--------------------------------------------------------------------------------
/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/main/res/drawable-v21/ic_notifications_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/src/main/res/drawable-v21/ic_sync_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
--------------------------------------------------------------------------------
/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Android/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/src/main/res/layout/content_client.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/main/res/layout/content_calender_test.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/src/main/res/layout/content_animation_gif.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # IOT-Raspberry-Pi-Android-App
2 | IOT Raspberry Pi android application available for download at - https://play.google.com/store/apps/details?id=com.mithu.mithunmistry.mithun&hl=en
3 |
4 | Watch the videos at -
5 | Raspberry Pi to Android : https://youtu.be/x7LvRoGbaDc
6 | Home Automation project : https://youtu.be/UxJIQw1Ubi8
7 |
8 | Modify the app as per need for your project. This is an open-source project meant for people to learn. Using it for commercial project is
9 | strictly prohibited and can incur legal action. This is free to use for educational purpose only.
10 |
11 | * This App was made from October-2015 till June-2016 and is no longer maintained.
12 | * If we want to use ready made library, see my Socket.IO-Usage-Demo-Android repository - https://github.com/mithunjmistry/Socket.IO-Usage-Demo-Android
13 |
--------------------------------------------------------------------------------
/src/main/res/layout/fragment_two.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
8 |
9 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/main/res/layout/fragment_three.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
9 |
10 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/main/res/layout/fragment_one.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
14 |
15 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/src/main/res/xml/pref_headers.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
8 |
9 |
13 |
14 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/main/res/layout/content_todo.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/main/res/layout/item_todo.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
15 |
16 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/src/main/java/com/mithu/mithunmistry/mithun/OneFragment.java:
--------------------------------------------------------------------------------
1 | package com.mithu.mithunmistry.mithun;
2 |
3 | import android.app.Activity;
4 | import android.net.Uri;
5 | import android.os.Bundle;
6 | import android.support.v4.app.Fragment;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 |
11 |
12 | /**
13 | * A simple {@link Fragment} subclass.
14 | * Activities that contain this fragment must implement the
15 | * {@link OneFragment.OnFragmentInteractionListener} interface
16 | * to handle interaction events.
17 | * Use the {@link OneFragment#newInstance} factory method to
18 | * create an instance of this fragment.
19 | */
20 | public class OneFragment extends Fragment {
21 |
22 | @Override
23 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
24 | Bundle savedInstanceState) {
25 | // Inflate the layout for this fragment
26 | return inflater.inflate(R.layout.fragment_one, container, false);
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/com/mithu/mithunmistry/mithun/TwoFragment.java:
--------------------------------------------------------------------------------
1 | package com.mithu.mithunmistry.mithun;
2 |
3 | import android.app.Activity;
4 | import android.net.Uri;
5 | import android.os.Bundle;
6 |
7 | import android.support.v4.app.Fragment;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 |
12 |
13 | /**
14 | * A simple {@link Fragment} subclass.
15 | * Activities that contain this fragment must implement the
16 | * {@link TwoFragment.OnFragmentInteractionListener} interface
17 | * to handle interaction events.
18 | * Use the {@link TwoFragment#newInstance} factory method to
19 | * create an instance of this fragment.
20 | */
21 | public class TwoFragment extends Fragment {
22 |
23 | @Override
24 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
25 | Bundle savedInstanceState) {
26 | // Inflate the layout for this fragment
27 | return inflater.inflate(R.layout.fragment_two, container, false);
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/res/xml/pref_data_sync.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
14 |
15 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/src/main/java/com/mithu/mithunmistry/mithun/ThreeFragment.java:
--------------------------------------------------------------------------------
1 | package com.mithu.mithunmistry.mithun;
2 |
3 | import android.app.Activity;
4 | import android.net.Uri;
5 | import android.os.Bundle;
6 | import android.support.v4.app.Fragment;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 |
11 |
12 | /**
13 | * A simple {@link Fragment} subclass.
14 | * Activities that contain this fragment must implement the
15 | * {@link ThreeFragment.OnFragmentInteractionListener} interface
16 | * to handle interaction events.
17 | * Use the {@link ThreeFragment#newInstance} factory method to
18 | * create an instance of this fragment.
19 | */
20 | public class ThreeFragment extends Fragment {
21 |
22 | @Override
23 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
24 | Bundle savedInstanceState) {
25 | // Inflate the layout for this fragment
26 | return inflater.inflate(R.layout.fragment_three, container, false);
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/com/mithu/mithunmistry/mithun/animationGif.java:
--------------------------------------------------------------------------------
1 | package com.mithu.mithunmistry.mithun;
2 |
3 | import android.content.Intent;
4 | import android.graphics.Color;
5 | import android.os.Bundle;
6 | import android.support.design.widget.FloatingActionButton;
7 | import android.support.design.widget.Snackbar;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.support.v7.widget.Toolbar;
10 | import android.view.SurfaceView;
11 | import android.view.View;
12 |
13 |
14 | import java.util.logging.Handler;
15 | import java.util.logging.LogRecord;
16 |
17 | //import pl.droidsonroids.gif.GifImageView;
18 |
19 | public class animationGif extends AppCompatActivity {
20 | //GifImageView micky2;
21 |
22 | @Override
23 | protected void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | setContentView(R.layout.activity_animation_gif);
26 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
27 | //micky2 = (GifImageView) findViewById(R.id.view);
28 |
29 |
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/com/mithu/mithunmistry/mithun/PagerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.mithu.mithunmistry.mithun;
2 |
3 | import android.support.v4.app.Fragment;
4 | import android.support.v4.app.FragmentManager;
5 | import android.support.v4.app.FragmentStatePagerAdapter;
6 |
7 | public class PagerAdapter extends FragmentStatePagerAdapter {
8 | int mNumOfTabs;
9 |
10 | public PagerAdapter(FragmentManager fm, int NumOfTabs) {
11 | super(fm);
12 | this.mNumOfTabs = NumOfTabs;
13 | }
14 |
15 | @Override
16 | public Fragment getItem(int position) {
17 |
18 | switch (position) {
19 | case 0:
20 | OneFragment tab1 = new OneFragment();
21 | return tab1;
22 | case 1:
23 | TwoFragment tab2 = new TwoFragment();
24 | return tab2;
25 | case 2:
26 | ThreeFragment tab3 = new ThreeFragment();
27 | return tab3;
28 | default:
29 | return null;
30 | }
31 | }
32 |
33 | @Override
34 | public int getCount() {
35 | return mNumOfTabs;
36 | }
37 | }
--------------------------------------------------------------------------------
/src/main/java/com/mithu/mithunmistry/mithun/todo.java:
--------------------------------------------------------------------------------
1 | package com.mithu.mithunmistry.mithun;
2 |
3 | import android.os.Bundle;
4 | import android.support.design.widget.FloatingActionButton;
5 | import android.support.design.widget.Snackbar;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.support.v7.widget.Toolbar;
8 | import android.view.View;
9 |
10 | public class todo extends AppCompatActivity {
11 |
12 | @Override
13 | protected void onCreate(Bundle savedInstanceState) {
14 | super.onCreate(savedInstanceState);
15 | setContentView(R.layout.activity_todo);
16 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
17 | setSupportActionBar(toolbar);
18 |
19 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
20 | fab.setOnClickListener(new View.OnClickListener() {
21 | @Override
22 | public void onClick(View view) {
23 | Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
24 | .setAction("Action", null).show();
25 | }
26 | });
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/com/mithu/mithunmistry/mithun/calenderTest.java:
--------------------------------------------------------------------------------
1 | package com.mithu.mithunmistry.mithun;
2 |
3 | import android.os.Bundle;
4 | import android.support.design.widget.FloatingActionButton;
5 | import android.support.design.widget.Snackbar;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.support.v7.widget.Toolbar;
8 | import android.view.View;
9 | import android.widget.CalendarView;
10 | import android.widget.Toast;
11 |
12 | import java.util.Calendar;
13 |
14 | public class calenderTest extends AppCompatActivity {
15 | CalendarView calendar;
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_calender_test);
21 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
22 | setSupportActionBar(toolbar);
23 |
24 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
25 | fab.setOnClickListener(new View.OnClickListener() {
26 | @Override
27 | public void onClick(View view) {
28 | Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
29 | .setAction("Action", null).show();
30 | }
31 | });
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/com/mithu/mithunmistry/mithun/VoiceHelp.java:
--------------------------------------------------------------------------------
1 | package com.mithu.mithunmistry.mithun;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.design.widget.FloatingActionButton;
6 | import android.support.design.widget.Snackbar;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.support.v7.widget.Toolbar;
9 | import android.view.View;
10 |
11 | public class VoiceHelp extends AppCompatActivity {
12 |
13 | @Override
14 | protected void onCreate(Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | setContentView(R.layout.activity_voice_help);
17 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
18 | setSupportActionBar(toolbar);
19 |
20 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
21 | fab.setOnClickListener(new View.OnClickListener() {
22 | @Override
23 | public void onClick(View view) {
24 | Snackbar.make(view, "Developed by Mithun", Snackbar.LENGTH_LONG)
25 | .setAction("Action", null).show();
26 | }
27 | });
28 | }
29 |
30 | public void onBackPressed() {
31 | Intent intent = new Intent(this, Main2Activity.class);
32 | startActivity(intent);
33 | finish();
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/main/res/xml/pref_notification.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
9 |
10 |
11 |
12 |
13 |
19 |
20 |
21 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/src/main/res/layout/activity_todo.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
14 |
15 |
16 |
17 |
24 |
25 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/src/main/res/layout/activity_client.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/main/res/layout/activity_ip.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/main/res/layout/activity_pid.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/main/res/layout/activity_tab.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/main/res/layout/activity_level.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/main/res/layout/activity_main2.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/main/res/layout/activity_main3.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/main/res/layout/activity_main4.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/main/res/layout/activity_main22.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/main/res/layout/activity_experiment.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/main/res/layout/activity_experiment2.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/main/res/layout/activity_humidity.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/main/res/layout/activity_moisture.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/main/res/layout/activity_voice_help.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/main/res/layout/activity_animation_gif.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/main/res/layout/activity_calender_test.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/main/res/layout/activity_new_socket.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/main/res/layout/activity_parameter.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/main/res/layout/activity_raspberry_pi.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/main/res/layout/content_new_socket.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
19 |
20 |
29 |
30 |
--------------------------------------------------------------------------------
/src/main/res/layout/activity_temperature.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/main/res/layout/activity_outputcontrol.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/main/java/com/mithu/mithunmistry/mithun/Main4Activity.java:
--------------------------------------------------------------------------------
1 | package com.mithu.mithunmistry.mithun;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.design.widget.FloatingActionButton;
6 | import android.support.design.widget.Snackbar;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.support.v7.widget.Toolbar;
9 | import android.view.View;
10 |
11 | public class Main4Activity extends AppCompatActivity {
12 |
13 |
14 | @Override
15 | protected void onCreate(Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | setContentView(R.layout.activity_main4);
18 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
19 | setSupportActionBar(toolbar);
20 |
21 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
22 | fab.setOnClickListener(new View.OnClickListener() {
23 | @Override
24 | public void onClick(View view) {
25 | Snackbar.make(view, "Developed by Mithun", Snackbar.LENGTH_LONG)
26 | .setAction("Action", null);
27 | }
28 | });
29 | }
30 |
31 | public void experimentalPage(View view){
32 | Intent intent = new Intent(this, experiment2.class);
33 | startActivity(intent);
34 | }
35 |
36 | public void onBackPressed() {
37 | Intent intent = new Intent(this, Main2Activity.class);
38 | startActivity(intent);
39 | finish();
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/res/xml/pref_general.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
10 |
11 |
20 |
21 |
23 |
24 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/src/main/res/layout/content_tab.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
21 |
22 |
31 |
32 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/src/main/res/layout/content_moisture.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
18 |
19 |
26 |
27 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/src/main/res/layout/content_humidity.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
18 |
19 |
26 |
27 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/src/main/res/layout/content_level.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
19 |
20 |
28 |
29 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/src/main/java/com/mithu/mithunmistry/mithun/ParameterActivity.java:
--------------------------------------------------------------------------------
1 | package com.mithu.mithunmistry.mithun;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.design.widget.FloatingActionButton;
6 | import android.support.design.widget.Snackbar;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.support.v7.widget.Toolbar;
9 | import android.view.View;
10 |
11 | public class ParameterActivity extends AppCompatActivity {
12 |
13 | @Override
14 | protected void onCreate(Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | setContentView(R.layout.activity_parameter);
17 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
18 | setSupportActionBar(toolbar);
19 |
20 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
21 | fab.setOnClickListener(new View.OnClickListener() {
22 | @Override
23 | public void onClick(View view) {
24 | Snackbar.make(view, "Developed by Mithun", Snackbar.LENGTH_LONG)
25 | .setAction("Action", null);
26 | }
27 | });
28 | }
29 |
30 | public void temperature(View view){
31 | Intent intent = new Intent(this, TemperatureActivity.class);
32 | startActivity(intent);
33 | }
34 |
35 | public void humidity(View view){
36 | Intent intent = new Intent(this, HumidityActivity.class);
37 | startActivity(intent);
38 | }
39 |
40 | public void level(View view){
41 | Intent intent = new Intent(this, LevelActivity.class);
42 | startActivity(intent);
43 | }
44 |
45 | public void moisture(View view){
46 | Intent intent = new Intent(this, MoistureActivity.class);
47 | startActivity(intent);
48 | }
49 |
50 | public void onBackPressed() {
51 | Intent intent = new Intent(this, Main2Activity.class);
52 | startActivity(intent);
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/res/layout/content_pid.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
21 |
22 |
33 |
34 |
42 |
43 |
--------------------------------------------------------------------------------
/src/main/res/layout/content_main3.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
22 |
23 |
32 |
33 |
44 |
45 |
--------------------------------------------------------------------------------
/src/main/res/layout/activity_fan_speed.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
16 |
17 |
24 |
25 |
33 |
34 |
41 |
42 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/src/main/res/layout/activity_brightness_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
15 |
16 |
24 |
25 |
34 |
35 |
42 |
43 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/src/main/res/layout/content_main22.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
20 |
25 |
30 |
36 |
42 |
46 |
47 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/src/main/res/layout/content_experiment.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
17 |
18 |
23 |
24 |
29 |
30 |
36 |
37 |
44 |
45 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/src/main/res/layout/content_ip.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
17 |
18 |
25 |
26 |
32 |
33 |
40 |
41 |
49 |
50 |
56 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/src/main/java/com/mithu/mithunmistry/mithun/LineGraph.java:
--------------------------------------------------------------------------------
1 | package com.mithu.mithunmistry.mithun;
2 |
3 | import org.achartengine.ChartFactory;
4 | import org.achartengine.GraphicalView;
5 | import org.achartengine.chart.PointStyle;
6 | import org.achartengine.model.TimeSeries;
7 | import org.achartengine.model.XYMultipleSeriesDataset;
8 | import org.achartengine.renderer.SimpleSeriesRenderer;
9 | import org.achartengine.renderer.XYMultipleSeriesRenderer;
10 | import org.achartengine.renderer.XYSeriesRenderer;
11 |
12 | import android.content.Context;
13 | import android.graphics.Color;
14 | import android.graphics.Paint;
15 |
16 | public class LineGraph {
17 |
18 | private GraphicalView view;
19 |
20 | private TimeSeries dataset = new TimeSeries("Temperature statistics-");
21 | private XYMultipleSeriesDataset mDataset = new XYMultipleSeriesDataset();
22 |
23 | private XYSeriesRenderer renderer = new XYSeriesRenderer(); // This will be used to customize line 1
24 | private XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer(); // Holds a collection of XYSeriesRenderer and customizes the graph
25 |
26 | public LineGraph()
27 | {
28 | // Add single dataset to multiple dataset
29 | mDataset.addSeries(dataset);
30 |
31 | // Customization time for line 1!
32 | renderer.setColor(Color.YELLOW);
33 | renderer.setPointStyle(PointStyle.CIRCLE);
34 | renderer.setFillPoints(true);
35 |
36 | // Enable Zoom
37 | mRenderer.setZoomButtonsVisible(true);
38 | mRenderer.setXTitle("Time (in seconds)");
39 | mRenderer.setYTitle("Temperature");
40 | //mRenderer.setYAxisMin(10);
41 | //mRenderer.setYAxisMax(50);
42 | mRenderer.setAxisTitleTextSize(24);
43 | mRenderer.setZoomEnabled(true, true);
44 | mRenderer.setBackgroundColor(Color.BLACK);
45 | mRenderer.setApplyBackgroundColor(true);
46 | //mRenderer.setGridColor(Color.WHITE);
47 | //mRenderer.setShowGrid(true);
48 | mRenderer.setChartTitle("Temperature variation - ");
49 | mRenderer.setChartTitleTextSize(26);
50 |
51 | // Add single renderer to multiple renderer
52 | mRenderer.addSeriesRenderer(renderer);
53 | }
54 |
55 | public GraphicalView getView(Context context)
56 | {
57 | view = ChartFactory.getLineChartView(context, mDataset, mRenderer);
58 | return view;
59 | }
60 |
61 | public void addNewPoints(Point p) {
62 | dataset.add(p.getX(), p.getY());
63 | }
64 | }
65 |
66 |
--------------------------------------------------------------------------------
/src/main/res/layout/content_temperature.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
18 |
19 |
26 |
27 |
35 |
36 |
44 |
45 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/src/main/res/layout/content_parameter.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
17 |
18 |
23 |
24 |
32 |
33 |
40 |
41 |
42 |
47 |
48 |
56 |
57 |
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
16 |
17 |
24 |
25 |
29 |
30 |
35 |
36 |
41 |
42 |
43 |
44 |
50 |
51 |
56 |
57 |
63 |
64 |
70 |
71 |
77 |
78 |
87 |
88 |
89 |
90 |
91 |
--------------------------------------------------------------------------------
/src/main/res/layout/content_outputcontrol.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
17 |
18 |
26 |
27 |
35 |
36 |
44 |
45 |
53 |
54 |
62 |
63 |
71 |
72 |
80 |
81 |
89 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/src/main/java/com/mithu/mithunmistry/mithun/NewSocketActivity.java:
--------------------------------------------------------------------------------
1 | package com.mithu.mithunmistry.mithun;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.os.Handler;
6 | import android.support.design.widget.FloatingActionButton;
7 | import android.support.design.widget.Snackbar;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.support.v7.widget.Toolbar;
10 | import android.text.TextUtils;
11 | import android.util.Log;
12 | import android.view.View;
13 | import android.widget.EditText;
14 | import com.github.nkzawa.socketio.client.IO;
15 | import com.github.nkzawa.socketio.client.Socket;
16 | import com.github.nkzawa.emitter.Emitter;
17 |
18 | import org.json.JSONException;
19 | import org.json.JSONObject;
20 |
21 | import java.net.URISyntaxException;
22 |
23 | public class NewSocketActivity extends AppCompatActivity {
24 | EditText newSocketText;
25 |
26 | @Override
27 | protected void onCreate(Bundle savedInstanceState) {
28 |
29 | super.onCreate(savedInstanceState);
30 | setContentView(R.layout.activity_new_socket);
31 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
32 | newSocketText = (EditText) findViewById(R.id.newSocketText);
33 | mSocket.connect();
34 | mSocket.on("new message", onNewMessage);
35 | listen();
36 |
37 |
38 |
39 |
40 |
41 | setSupportActionBar(toolbar);
42 |
43 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
44 | fab.setOnClickListener(new View.OnClickListener() {
45 | @Override
46 | public void onClick(View view) {
47 | Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
48 | .setAction("Action", null).show();
49 | }
50 | });
51 | }
52 |
53 | private Socket mSocket;
54 | {
55 | try {
56 | mSocket = IO.socket("http://192.168.1.101:5002");
57 | } catch (URISyntaxException e) {}
58 | }
59 |
60 | public void attemptSend(View view) {
61 | String message = newSocketText.getText().toString().trim();
62 | if (TextUtils.isEmpty(message)) {
63 | return;
64 | }
65 |
66 | newSocketText.setText("");
67 | mSocket.emit("chat message", message);
68 | }
69 |
70 | public void listen(){
71 | Handler handler = new Handler();
72 | handler.postDelayed(new Runnable() {
73 | @Override
74 | public void run() {
75 | // do something
76 | mSocket.emit("chat message", "cool");
77 | listening();
78 | }
79 | }, 1);
80 | }
81 |
82 | public void listening() {
83 | // mSocket.on("new message", onNewMessage);
84 | Log.d("running continously", "indefinite");
85 | listen();
86 | }
87 |
88 |
89 | private Runnable predrePhotoRunnable = new Runnable() {
90 | public void run() {
91 |
92 | }
93 | };
94 |
95 | public Emitter.Listener onNewMessage = new Emitter.Listener() {
96 | @Override
97 | public void call(final Object... args) {
98 | Log.d("loop", "entered listening loop");
99 | (NewSocketActivity.this).runOnUiThread(new Runnable() {
100 | @Override
101 | public void run() {
102 | String data = (String) args[0];
103 | /*String username;
104 | //String message;
105 | try {
106 | username = data.getString("mithun");
107 | //message = data.getString("message");
108 | } catch (JSONException e) {
109 | return;
110 | }
111 |
112 | // add the message to view*/
113 | newSocketText.setText(data);
114 | }
115 | });
116 | }
117 | };
118 | }
119 |
--------------------------------------------------------------------------------
/src/main/res/layout/content_main4.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
15 |
16 |
20 |
21 |
25 |
26 |
36 |
37 |
51 |
52 |
62 |
63 |
78 |
79 |
89 |
90 |
103 |
104 |
105 |
106 |
107 |
116 |
117 |
--------------------------------------------------------------------------------
/src/main/java/com/mithu/mithunmistry/mithun/MockData.java:
--------------------------------------------------------------------------------
1 | package com.mithu.mithunmistry.mithun;
2 |
3 | /**
4 | * Created by Mithun Mistry on 27-04-2016.
5 | */
6 | import android.content.SharedPreferences;
7 | import android.os.AsyncTask;
8 | import android.preference.PreferenceManager;
9 | import android.support.v7.app.AppCompatActivity;
10 | import android.view.View;
11 |
12 | import java.io.BufferedWriter;
13 | import java.io.IOException;
14 | import java.io.InputStream;
15 | import java.io.OutputStreamWriter;
16 | import java.io.PrintWriter;
17 | import java.net.InetAddress;
18 | import java.net.Socket;
19 | import java.net.UnknownHostException;
20 | import java.util.Random;
21 | import java.util.Timer;
22 | import java.util.TimerTask;
23 |
24 | public class MockData{
25 | Timer timer;
26 | TimerTask timerTask;
27 | int SERVERPORT = 6000;
28 | String SERVER_IP = "192.168.56.1";
29 | Socket socket;
30 | Integer x = 1;
31 | Integer ic = 1;
32 | String message = "graphtemp";
33 | static int c = 30;
34 |
35 | public void create() {
36 |
37 |
38 | //SharedPreferences portip = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
39 | //String ipr = portip.getString("IP", "192.168.1.100");
40 | //int portr = portip.getInt("Port", 6000);
41 | //Log.d("test", test1);
42 | //SERVER_IP = ipr;
43 | //SERVERPORT = portr;
44 | ic = 1;
45 | startTimer();
46 | }
47 |
48 | // x is the day number, 0, 1, 2, 3
49 | public static Point getDataFromReceiver(int x)
50 | {
51 | return new Point(x, tempData());
52 | }
53 |
54 | private static int tempData(){
55 | return c;
56 | }
57 |
58 | public void startTimer() {
59 | //set a new Timer
60 | timer = new Timer();
61 | //initialize the TimerTask's job
62 | initializeTimerTask();
63 | //schedule the timer, after the first 5000ms the TimerTask will run every 10000ms
64 | timer.schedule(timerTask, 100, 4000); //
65 | }
66 |
67 | public void stoptimertask(View v) {
68 | //stop the timer, if it's not already null
69 | if (timer != null) {
70 | timer.cancel();
71 | timer = null;
72 | }
73 | }
74 |
75 |
76 |
77 | public void initializeTimerTask() {
78 | timerTask = new TimerTask() {
79 | public void run() {
80 | //use a handler to run a toast that shows the current timestamp
81 | new Thread(new ClientThread()).start();
82 | try {
83 | String str = message;
84 |
85 | PrintWriter out = new PrintWriter(new BufferedWriter(
86 | new OutputStreamWriter(socket.getOutputStream())), true);
87 | out.println(str);
88 | out.flush();
89 | } catch (UnknownHostException e) {
90 | e.printStackTrace();
91 | } catch (IOException e) {
92 | e.printStackTrace();
93 | } catch (Exception e) {
94 | e.printStackTrace();
95 | }
96 | new ConnectionTask().execute();
97 |
98 | }
99 | };
100 | }
101 | class ConnectionTask extends AsyncTask {
102 |
103 | protected String doInBackground(String... params) {
104 | String responce = null;
105 | try {
106 |
107 | InputStream input = socket.getInputStream();
108 | int lockSeconds = 10 * 1000;
109 |
110 | long lockThreadCheckpoint = System.currentTimeMillis();
111 | int availableBytes = input.available();
112 | while (availableBytes <= 0 && (System.currentTimeMillis() < lockThreadCheckpoint + lockSeconds)) {
113 | try {
114 | Thread.sleep(10);
115 | } catch (InterruptedException ie) {
116 | ie.printStackTrace();
117 | }
118 | availableBytes = input.available();
119 | }
120 |
121 | byte[] buffer = new byte[availableBytes];
122 | input.read(buffer, 0, availableBytes);
123 | responce = new String(buffer);
124 |
125 | //out.close();
126 | input.close();
127 | socket.close();
128 | } catch (UnknownHostException e) {
129 | e.printStackTrace();
130 | } catch (IOException e) {
131 | e.printStackTrace();
132 | } catch (Exception e) {
133 | e.printStackTrace();
134 | }
135 | return responce;
136 | }
137 |
138 | protected void onPostExecute(String responce) {
139 | if (ic.intValue() == x.intValue()) {
140 |
141 | if (responce != null) {
142 | c = Integer.parseInt(responce);
143 |
144 |
145 | } else {
146 | message = "graphtemp";
147 | }
148 |
149 |
150 | }
151 | else{
152 |
153 | }
154 | }
155 |
156 |
157 | }
158 |
159 |
160 | class ClientThread implements Runnable {
161 |
162 | @Override
163 | public void run() {
164 | if (ic.intValue() == x.intValue()) {
165 |
166 | try {
167 | InetAddress serverAddr = InetAddress.getByName(SERVER_IP);
168 |
169 | socket = new Socket(serverAddr, SERVERPORT);
170 |
171 | } catch (UnknownHostException e1) {
172 | e1.printStackTrace();
173 | } catch (IOException e1) {
174 | e1.printStackTrace();
175 | }
176 |
177 | }
178 | else{
179 |
180 | }
181 |
182 | }
183 | }
184 |
185 | }
--------------------------------------------------------------------------------
/src/main/java/com/mithu/mithunmistry/mithun/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.mithu.mithunmistry.mithun;
2 |
3 | import android.app.AlertDialog;
4 | import android.content.DialogInterface;
5 | import android.content.Intent;
6 | import android.content.SharedPreferences;
7 | import android.os.Bundle;
8 | import android.preference.PreferenceManager;
9 | import android.support.design.widget.FloatingActionButton;
10 | import android.support.design.widget.Snackbar;
11 | import android.support.v7.app.AppCompatActivity;
12 | import android.support.v7.widget.Toolbar;
13 | import android.view.View;
14 | import android.view.Menu;
15 | import android.view.MenuItem;
16 | import android.widget.Button;
17 | import android.widget.CheckBox;
18 | import android.widget.EditText;
19 |
20 |
21 | public class MainActivity extends AppCompatActivity {
22 |
23 | EditText username;
24 | EditText password;
25 | Button access;
26 | CheckBox loggedIn;
27 | String uname = "mithunjmistry";
28 | String pwd = "raspberry";
29 | Boolean cbChecker;
30 |
31 | @Override
32 | protected void onCreate(Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 | setContentView(R.layout.activity_main);
35 | username = (EditText)findViewById(R.id.editText);
36 | password = (EditText)findViewById(R.id.editText2);
37 | //loggedIn = (CheckBox)findViewById(R.id.checkBox);
38 | username.setText("mithunjmistry");
39 | password.setFocusable(true);
40 | password.setFocusableInTouchMode(true);
41 | password.requestFocus();
42 |
43 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
44 | setSupportActionBar(toolbar);
45 |
46 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
47 | fab.setOnClickListener(new View.OnClickListener() {
48 | @Override
49 | public void onClick(View view) {
50 | Snackbar.make(view, "Default password is 'raspberry'", Snackbar.LENGTH_SHORT)
51 | .setAction("Action", null).show();
52 | }
53 | });
54 | }
55 |
56 | @Override
57 | public boolean onCreateOptionsMenu(Menu menu) {
58 | // Inflate the menu; this adds items to the action bar if it is present.
59 | getMenuInflater().inflate(R.menu.menu_main, menu);
60 | return true;
61 | }
62 |
63 | @Override
64 | public boolean onOptionsItemSelected(MenuItem item) {
65 | // Handle action bar item clicks here. The action bar will
66 | // automatically handle clicks on the Home/Up button, so long
67 | // as you specify a parent activity in AndroidManifest.xml.
68 | int id = item.getItemId();
69 |
70 | //noinspection SimplifiableIfStatement
71 | if (id == R.id.action_settings) {
72 | return true;
73 | }
74 |
75 | return super.onOptionsItemSelected(item);
76 | }
77 |
78 | public void attemptLogin(View view)
79 | {
80 | //loggedIn = (CheckBox)findViewById(R.id.checkBox);
81 | String entereduname = username.getText().toString();
82 | String enteredpwd = password.getText().toString();
83 |
84 | if(uname.equals(entereduname) && pwd.equals(enteredpwd))
85 | {
86 | /*if (loggedIn.isChecked()) {
87 | SharedPreferences logactivity = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
88 | SharedPreferences.Editor editor = logactivity.edit();
89 | editor.putBoolean("Login Check", false);
90 | editor.commit();
91 | Intent intent = new Intent(this, Main2Activity.class);
92 | startActivity(intent);
93 | }
94 | else{
95 | Intent intent = new Intent(this, Main2Activity.class);
96 | startActivity(intent);
97 | }*/
98 | login();
99 | }
100 | else
101 | {
102 | AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
103 | password.setText("");
104 |
105 | dlgAlert.setMessage("Incorrect password or username");
106 | dlgAlert.setTitle("Try Again");
107 | dlgAlert.setPositiveButton("OK", null);
108 | dlgAlert.setCancelable(true);
109 | dlgAlert.create().show();
110 |
111 | dlgAlert.setPositiveButton("Ok",
112 | new DialogInterface.OnClickListener() {
113 | public void onClick(DialogInterface dialog, int which) {
114 |
115 | }
116 | });
117 | }
118 |
119 | }
120 |
121 | @Override
122 | public void onBackPressed() {
123 | new android.support.v7.app.AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle("Exit")
124 | .setMessage("Are you sure you want to exit?")
125 | .setNegativeButton("No", null)
126 | .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
127 | @Override
128 | public void onClick(DialogInterface dialog, int which) {
129 | Intent intent1 = new Intent(Intent.ACTION_MAIN);
130 | intent1.addCategory(Intent.CATEGORY_HOME);
131 | intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
132 | startActivity(intent1);
133 | }
134 | }).show();
135 |
136 | }
137 |
138 | private void login(){
139 | loggedIn = (CheckBox)findViewById(R.id.checkBox);
140 | if (loggedIn.isChecked()) {
141 | SharedPreferences logactivity = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
142 | SharedPreferences.Editor editor = logactivity.edit();
143 | editor.putBoolean("Login Check", false);
144 | editor.commit();
145 | Intent intent = new Intent(this, IpActivity.class);
146 | startActivity(intent);
147 | }
148 | else{
149 | SharedPreferences logactivity1 = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
150 | SharedPreferences.Editor editor = logactivity1.edit();
151 | editor.putBoolean("Login Check Transient", false);
152 | editor.commit();
153 | Intent intent = new Intent(this, IpActivity.class);
154 | startActivity(intent);
155 | }
156 | }
157 | }
158 |
--------------------------------------------------------------------------------
/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 | />
10 |
16 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
31 |
32 |
36 |
37 |
41 |
42 |
46 |
47 |
51 |
52 |
53 |
54 |
55 |
56 |
60 |
61 |
65 |
66 |
71 |
72 |
76 |
77 |
81 |
82 |
86 |
87 |
91 |
92 |
96 |
97 |
101 |
102 |
106 |
107 |
111 |
112 |
116 |
117 |
122 |
123 |
127 |
128 |
132 |
133 |
137 |
138 |
142 |
143 |
147 |
148 |
152 |
153 |
154 |
155 |
156 |
--------------------------------------------------------------------------------
/src/main/java/com/mithu/mithunmistry/mithun/PidActivity.java:
--------------------------------------------------------------------------------
1 | package com.mithu.mithunmistry.mithun;
2 |
3 | import android.content.Intent;
4 | import android.content.SharedPreferences;
5 | import android.os.AsyncTask;
6 | import android.os.Bundle;
7 | import android.preference.PreferenceManager;
8 | import android.support.design.widget.FloatingActionButton;
9 | import android.support.design.widget.Snackbar;
10 | import android.support.v7.app.AppCompatActivity;
11 | import android.support.v7.widget.Toolbar;
12 | import android.view.View;
13 | import android.widget.EditText;
14 |
15 | import java.io.BufferedWriter;
16 | import java.io.IOException;
17 | import java.io.InputStream;
18 | import java.io.OutputStreamWriter;
19 | import java.io.PrintWriter;
20 | import java.net.InetAddress;
21 | import java.net.Socket;
22 | import java.net.UnknownHostException;
23 | import java.util.Timer;
24 | import java.util.TimerTask;
25 |
26 | public class PidActivity extends AppCompatActivity {
27 |
28 | Socket socket;
29 | Integer ic = 1;
30 | Integer x = 1;
31 | int SERVERPORT = 6000;
32 | String SERVER_IP = "192.168.1.100";
33 | String message = "pid";
34 | Timer timer;
35 | TimerTask timerTask;
36 | EditText spPID;
37 |
38 | @Override
39 | protected void onCreate(Bundle savedInstanceState) {
40 | super.onCreate(savedInstanceState);
41 | setContentView(R.layout.activity_pid);
42 | SharedPreferences portip = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
43 | String ipr = portip.getString("IP", "192.168.1.100");
44 | int portr = portip.getInt("Port", 6000);
45 | //Log.d("test", test1);
46 | SERVER_IP = ipr;
47 | SERVERPORT = portr;
48 | spPID = (EditText)findViewById(R.id.spPID);
49 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
50 | setSupportActionBar(toolbar);
51 | ic = 1;
52 | startTimer();
53 |
54 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
55 | fab.setOnClickListener(new View.OnClickListener() {
56 | @Override
57 | public void onClick(View view) {
58 | Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
59 | .setAction("Action", null).show();
60 | }
61 | });
62 | }
63 |
64 | public void setPointPID(View view){
65 | message = spPID.getText().toString();
66 | }
67 |
68 | @Override
69 | public void onBackPressed() {
70 | ic = 0;
71 | Intent intent = new Intent(this, Main2Activity.class);
72 | startActivity(intent);
73 | finish();
74 | }
75 |
76 | public void startTimer() {
77 | //set a new Timer
78 | timer = new Timer();
79 | //initialize the TimerTask's job
80 | initializeTimerTask();
81 | //schedule the timer, after the first 5000ms the TimerTask will run every 10000ms
82 | timer.schedule(timerTask, 100, 2000); //
83 | }
84 |
85 | public void stoptimertask(View v) {
86 | //stop the timer, if it's not already null
87 | if (timer != null) {
88 | timer.cancel();
89 | timer = null;
90 | }
91 | }
92 |
93 | public void initializeTimerTask() {
94 | timerTask = new TimerTask() {
95 | public void run() {
96 | //use a handler to run a toast that shows the current timestamp
97 | new Thread(new ClientThread()).start();
98 | try {
99 | String str = message;
100 |
101 | PrintWriter out = new PrintWriter(new BufferedWriter(
102 | new OutputStreamWriter(socket.getOutputStream())), true);
103 | out.println(str);
104 | out.flush();
105 | } catch (UnknownHostException e) {
106 | e.printStackTrace();
107 | } catch (IOException e) {
108 | e.printStackTrace();
109 | } catch (Exception e) {
110 | e.printStackTrace();
111 | }
112 | new ConnectionTask().execute();
113 |
114 | }
115 | };
116 | }
117 | class ConnectionTask extends AsyncTask {
118 |
119 | protected String doInBackground(String... params) {
120 | String responce = null;
121 | try {
122 |
123 | InputStream input = socket.getInputStream();
124 | int lockSeconds = 10 * 1000;
125 |
126 | long lockThreadCheckpoint = System.currentTimeMillis();
127 | int availableBytes = input.available();
128 | while (availableBytes <= 0 && (System.currentTimeMillis() < lockThreadCheckpoint + lockSeconds)) {
129 | try {
130 | Thread.sleep(10);
131 | } catch (InterruptedException ie) {
132 | ie.printStackTrace();
133 | }
134 | availableBytes = input.available();
135 | }
136 |
137 | byte[] buffer = new byte[availableBytes];
138 | input.read(buffer, 0, availableBytes);
139 | responce = new String(buffer);
140 |
141 | //out.close();
142 | input.close();
143 | socket.close();
144 | } catch (UnknownHostException e) {
145 | e.printStackTrace();
146 | } catch (IOException e) {
147 | e.printStackTrace();
148 | } catch (Exception e) {
149 | e.printStackTrace();
150 | }
151 | return responce;
152 | }
153 |
154 | protected void onPostExecute(String responce) {
155 | if (responce != null) {
156 | message = "pid";
157 |
158 | }
159 | else{
160 | //message = "door";
161 | }
162 |
163 |
164 | }
165 | }
166 |
167 | class ClientThread implements Runnable {
168 |
169 | @Override
170 | public void run() {
171 | if (ic.intValue() == x.intValue()) {
172 |
173 | try {
174 | InetAddress serverAddr = InetAddress.getByName(SERVER_IP);
175 |
176 | socket = new Socket(serverAddr, SERVERPORT);
177 |
178 | } catch (UnknownHostException e1) {
179 | e1.printStackTrace();
180 | } catch (IOException e1) {
181 | e1.printStackTrace();
182 | }
183 |
184 | }
185 | else {
186 |
187 | }
188 |
189 | }
190 | }
191 |
192 | }
193 |
--------------------------------------------------------------------------------
/src/main/java/com/mithu/mithunmistry/mithun/MoistureActivity.java:
--------------------------------------------------------------------------------
1 | package com.mithu.mithunmistry.mithun;
2 |
3 | import android.content.Intent;
4 | import android.content.SharedPreferences;
5 | import android.os.AsyncTask;
6 | import android.os.Bundle;
7 | import android.preference.PreferenceManager;
8 | import android.support.design.widget.FloatingActionButton;
9 | import android.support.design.widget.Snackbar;
10 | import android.support.v7.app.AppCompatActivity;
11 | import android.support.v7.widget.Toolbar;
12 | import android.view.View;
13 | import android.widget.TextView;
14 |
15 | import java.io.BufferedWriter;
16 | import java.io.IOException;
17 | import java.io.InputStream;
18 | import java.io.OutputStreamWriter;
19 | import java.io.PrintWriter;
20 | import java.net.InetAddress;
21 | import java.net.Socket;
22 | import java.net.UnknownHostException;
23 | import java.util.Timer;
24 | import java.util.TimerTask;
25 |
26 | public class MoistureActivity extends AppCompatActivity {
27 | Timer timer;
28 | TimerTask timerTask;
29 | String message = "getmoisture";
30 | int SERVERPORT = 6000;
31 | String SERVER_IP = "192.168.1.100";
32 | Socket socket;
33 | Integer x = 1;
34 | Integer ic = 1;
35 | TextView moisture;
36 |
37 | @Override
38 | protected void onCreate(Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 | setContentView(R.layout.activity_moisture);
41 | SharedPreferences portip = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
42 | String ipr = portip.getString("IP", "192.168.1.100");
43 | int portr = portip.getInt("Port", 6000);
44 | //Log.d("test", test1);
45 | SERVER_IP = ipr;
46 | SERVERPORT = portr;
47 |
48 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
49 | setSupportActionBar(toolbar);
50 | moisture = (TextView)findViewById(R.id.moisture);
51 | ic = 1;
52 | startTimer();
53 |
54 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
55 | fab.setOnClickListener(new View.OnClickListener() {
56 | @Override
57 | public void onClick(View view) {
58 | Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
59 | .setAction("Action", null);
60 | }
61 | });
62 | }
63 |
64 | @Override
65 | public void onBackPressed() {
66 | message = "stop";
67 | ic = 0;
68 |
69 | Intent intent = new Intent(this, ParameterActivity.class);
70 | startActivity(intent);
71 | finish();
72 | }
73 |
74 | public void startTimer() {
75 | //set a new Timer
76 | timer = new Timer();
77 | //initialize the TimerTask's job
78 | initializeTimerTask();
79 | //schedule the timer, after the first 5000ms the TimerTask will run every 10000ms
80 | timer.schedule(timerTask, 100, 2000); //
81 | }
82 |
83 | public void stoptimertask(View v) {
84 | //stop the timer, if it's not already null
85 | if (timer != null) {
86 | timer.cancel();
87 | timer = null;
88 | }
89 | }
90 |
91 |
92 |
93 | public void initializeTimerTask() {
94 | timerTask = new TimerTask() {
95 | public void run() {
96 | //use a handler to run a toast that shows the current timestamp
97 | new Thread(new ClientThread()).start();
98 | try {
99 | String str = message;
100 |
101 | PrintWriter out = new PrintWriter(new BufferedWriter(
102 | new OutputStreamWriter(socket.getOutputStream())), true);
103 | out.println(str);
104 | out.flush();
105 | } catch (UnknownHostException e) {
106 | e.printStackTrace();
107 | } catch (IOException e) {
108 | e.printStackTrace();
109 | } catch (Exception e) {
110 | e.printStackTrace();
111 | }
112 | new ConnectionTask().execute();
113 |
114 | }
115 | };
116 | }
117 | class ConnectionTask extends AsyncTask {
118 |
119 | protected String doInBackground(String... params) {
120 | String responce = null;
121 | try {
122 |
123 | InputStream input = socket.getInputStream();
124 | int lockSeconds = 10 * 1000;
125 |
126 | long lockThreadCheckpoint = System.currentTimeMillis();
127 | int availableBytes = input.available();
128 | while (availableBytes <= 0 && (System.currentTimeMillis() < lockThreadCheckpoint + lockSeconds)) {
129 | try {
130 | Thread.sleep(10);
131 | } catch (InterruptedException ie) {
132 | ie.printStackTrace();
133 | }
134 | availableBytes = input.available();
135 | }
136 |
137 | byte[] buffer = new byte[availableBytes];
138 | input.read(buffer, 0, availableBytes);
139 | responce = new String(buffer);
140 |
141 | //out.close();
142 | input.close();
143 | socket.close();
144 | } catch (UnknownHostException e) {
145 | e.printStackTrace();
146 | } catch (IOException e) {
147 | e.printStackTrace();
148 | } catch (Exception e) {
149 | e.printStackTrace();
150 | }
151 | return responce;
152 | }
153 |
154 | protected void onPostExecute(String responce) {
155 |
156 | if (responce != null) {
157 | moisture.setText(responce + " %");
158 |
159 | } else {
160 | message = "getmoisture";
161 | }
162 |
163 |
164 | }
165 |
166 |
167 | }
168 |
169 |
170 | class ClientThread implements Runnable {
171 |
172 | @Override
173 | public void run() {
174 | if (ic.intValue() == x.intValue()) {
175 |
176 | try {
177 | InetAddress serverAddr = InetAddress.getByName(SERVER_IP);
178 |
179 | socket = new Socket(serverAddr, SERVERPORT);
180 |
181 | } catch (UnknownHostException e1) {
182 | e1.printStackTrace();
183 | } catch (IOException e1) {
184 | e1.printStackTrace();
185 | }
186 |
187 | }
188 | else{
189 |
190 | }
191 |
192 | }
193 | }
194 |
195 | }
196 |
--------------------------------------------------------------------------------
/src/main/java/com/mithu/mithunmistry/mithun/LevelActivity.java:
--------------------------------------------------------------------------------
1 | package com.mithu.mithunmistry.mithun;
2 |
3 | import android.content.Intent;
4 | import android.content.SharedPreferences;
5 | import android.os.AsyncTask;
6 | import android.os.Bundle;
7 | import android.preference.PreferenceManager;
8 | import android.support.design.widget.FloatingActionButton;
9 | import android.support.design.widget.Snackbar;
10 | import android.support.v7.app.AppCompatActivity;
11 | import android.support.v7.widget.Toolbar;
12 | import android.view.View;
13 | import android.widget.TextView;
14 |
15 | import java.io.BufferedWriter;
16 | import java.io.IOException;
17 | import java.io.InputStream;
18 | import java.io.OutputStreamWriter;
19 | import java.io.PrintWriter;
20 | import java.net.InetAddress;
21 | import java.net.Socket;
22 | import java.net.UnknownHostException;
23 | import java.util.Timer;
24 | import java.util.TimerTask;
25 |
26 | public class LevelActivity extends AppCompatActivity {
27 | Timer timer;
28 | TimerTask timerTask;
29 | String message = "getlevel";
30 | int SERVERPORT = 6000;
31 | String SERVER_IP = "192.168.1.100";
32 | Socket socket;
33 | Integer x = 1;
34 | Integer ic = 1;
35 | TextView level;
36 |
37 | @Override
38 | protected void onCreate(Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 | setContentView(R.layout.activity_level);
41 | SharedPreferences portip = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
42 | String ipr = portip.getString("IP", "192.168.1.100");
43 | int portr = portip.getInt("Port", 6000);
44 | //Log.d("test", test1);
45 | SERVER_IP = ipr;
46 | SERVERPORT = portr;
47 |
48 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
49 | setSupportActionBar(toolbar);
50 | level = (TextView)findViewById(R.id.level);
51 | ic = 1;
52 | startTimer();
53 |
54 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
55 | fab.setOnClickListener(new View.OnClickListener() {
56 | @Override
57 | public void onClick(View view) {
58 | Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
59 | .setAction("Action", null);
60 | }
61 | });
62 | }
63 |
64 | @Override
65 | public void onBackPressed() {
66 | ic = 0;
67 | Intent intent = new Intent(this, ParameterActivity.class);
68 | startActivity(intent);
69 | finish();
70 | }
71 |
72 | public void startTimer() {
73 | //set a new Timer
74 | timer = new Timer();
75 | //initialize the TimerTask's job
76 | initializeTimerTask();
77 | //schedule the timer, after the first 5000ms the TimerTask will run every 10000ms
78 | timer.schedule(timerTask, 100, 2000); //
79 | }
80 |
81 | public void stoptimertask(View v) {
82 | //stop the timer, if it's not already null
83 | if (timer != null) {
84 | timer.cancel();
85 | timer = null;
86 | }
87 | }
88 |
89 |
90 |
91 | public void initializeTimerTask() {
92 | timerTask = new TimerTask() {
93 | public void run() {
94 | //use a handler to run a toast that shows the current timestamp
95 | new Thread(new ClientThread()).start();
96 | try {
97 | String str = message;
98 |
99 | PrintWriter out = new PrintWriter(new BufferedWriter(
100 | new OutputStreamWriter(socket.getOutputStream())), true);
101 | out.println(str);
102 | out.flush();
103 | } catch (UnknownHostException e) {
104 | e.printStackTrace();
105 | } catch (IOException e) {
106 | e.printStackTrace();
107 | } catch (Exception e) {
108 | e.printStackTrace();
109 | }
110 | new ConnectionTask().execute();
111 |
112 | }
113 | };
114 | }
115 | class ConnectionTask extends AsyncTask {
116 |
117 | protected String doInBackground(String... params) {
118 | String responce = null;
119 | try {
120 |
121 | InputStream input = socket.getInputStream();
122 | int lockSeconds = 10 * 1000;
123 |
124 | long lockThreadCheckpoint = System.currentTimeMillis();
125 | int availableBytes = input.available();
126 | while (availableBytes <= 0 && (System.currentTimeMillis() < lockThreadCheckpoint + lockSeconds)) {
127 | try {
128 | Thread.sleep(10);
129 | } catch (InterruptedException ie) {
130 | ie.printStackTrace();
131 | }
132 | availableBytes = input.available();
133 | }
134 |
135 | byte[] buffer = new byte[availableBytes];
136 | input.read(buffer, 0, availableBytes);
137 | responce = new String(buffer);
138 |
139 | //out.close();
140 | input.close();
141 | socket.close();
142 | } catch (UnknownHostException e) {
143 | e.printStackTrace();
144 | } catch (IOException e) {
145 | e.printStackTrace();
146 | } catch (Exception e) {
147 | e.printStackTrace();
148 | }
149 | return responce;
150 | }
151 |
152 | protected void onPostExecute(String responce) {
153 |
154 | if (responce != null) {
155 | if (responce.equals("ufailed")){
156 | level.setText("Level sensor failed.");
157 | }
158 | else {
159 | level.setText(responce + " %");
160 | }
161 |
162 | } else {
163 | message = "getlevel";
164 | }
165 |
166 |
167 | }
168 |
169 |
170 | }
171 |
172 |
173 | class ClientThread implements Runnable {
174 |
175 | @Override
176 | public void run() {
177 | if (ic.intValue() == x.intValue()) {
178 |
179 | try {
180 | InetAddress serverAddr = InetAddress.getByName(SERVER_IP);
181 |
182 | socket = new Socket(serverAddr, SERVERPORT);
183 |
184 | } catch (UnknownHostException e1) {
185 | e1.printStackTrace();
186 | } catch (IOException e1) {
187 | e1.printStackTrace();
188 | }
189 |
190 | }
191 | else{
192 |
193 | }
194 |
195 | }
196 | }
197 |
198 | }
199 |
--------------------------------------------------------------------------------
/src/main/java/com/mithu/mithunmistry/mithun/TabActivity.java:
--------------------------------------------------------------------------------
1 | package com.mithu.mithunmistry.mithun;
2 |
3 | import android.os.AsyncTask;
4 | import android.os.Bundle;
5 | import android.support.design.widget.TabLayout;
6 | import android.support.v4.view.ViewPager;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.support.v7.widget.Toolbar;
9 | import android.view.Menu;
10 | import android.view.MenuItem;
11 | import android.view.View;
12 | import android.widget.TextView;
13 |
14 | import java.io.BufferedWriter;
15 | import java.io.IOException;
16 | import java.io.InputStream;
17 | import java.io.OutputStreamWriter;
18 | import java.io.PrintWriter;
19 | import java.net.InetAddress;
20 | import java.net.Socket;
21 | import java.net.UnknownHostException;
22 | import java.util.Timer;
23 | import java.util.TimerTask;
24 |
25 |
26 | public class TabActivity extends AppCompatActivity {
27 | Socket socket;
28 | static final int SERVERPORT = 6000;
29 | String SERVER_IP = "172.20.10.3";
30 | String message = "hello";
31 | Timer timer;
32 | TimerTask timerTask;
33 | TextView tab1;
34 |
35 | @Override
36 | protected void onCreate(Bundle savedInstanceState) {
37 | super.onCreate(savedInstanceState);
38 | setContentView(R.layout.activity_tab);
39 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
40 | setSupportActionBar(toolbar);
41 |
42 | TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
43 |
44 | tabLayout.addTab(tabLayout.newTab().setText("Tab 1"));
45 | tabLayout.addTab(tabLayout.newTab().setText("Tab 2"));
46 | tabLayout.addTab(tabLayout.newTab().setText("Tab 3"));
47 | tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
48 | tab1 = (TextView)findViewById(R.id.textView33);
49 | startTimer();
50 |
51 | final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
52 | final PagerAdapter adapter = new PagerAdapter
53 | (getSupportFragmentManager(), tabLayout.getTabCount());
54 | viewPager.setAdapter(adapter);
55 | viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
56 | tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
57 | @Override
58 | public void onTabSelected(TabLayout.Tab tab) {
59 | viewPager.setCurrentItem(tab.getPosition());
60 | }
61 |
62 | @Override
63 | public void onTabUnselected(TabLayout.Tab tab) {
64 |
65 | }
66 |
67 | @Override
68 | public void onTabReselected(TabLayout.Tab tab) {
69 |
70 | }
71 | });
72 | }
73 |
74 | @Override
75 | public boolean onCreateOptionsMenu(Menu menu) {
76 | getMenuInflater().inflate(R.menu.menu_main, menu);
77 | return true;
78 | }
79 |
80 | @Override
81 | public boolean onOptionsItemSelected(MenuItem item) {
82 | int id = item.getItemId();
83 | if (id == R.id.action_settings) {
84 | return true;
85 | }
86 |
87 | return super.onOptionsItemSelected(item);
88 | }
89 |
90 | public void startTimer() {
91 | //set a new Timer
92 | timer = new Timer();
93 | //initialize the TimerTask's job
94 | initializeTimerTask();
95 | //schedule the timer, after the first 5000ms the TimerTask will run every 10000ms
96 | timer.schedule(timerTask, 100, 2000); //
97 | }
98 |
99 | public void stoptimertask(View v) {
100 | //stop the timer, if it's not already null
101 | if (timer != null) {
102 | timer.cancel();
103 | timer = null;
104 | }
105 | }
106 |
107 | public void initializeTimerTask() {
108 | timerTask = new TimerTask() {
109 | public void run() {
110 | //use a handler to run a toast that shows the current timestamp
111 | new Thread(new ClientThread()).start();
112 | try {
113 | String str = message;
114 |
115 | PrintWriter out = new PrintWriter(new BufferedWriter(
116 | new OutputStreamWriter(socket.getOutputStream())), true);
117 | out.println(str);
118 | out.flush();
119 | } catch (UnknownHostException e) {
120 | e.printStackTrace();
121 | } catch (IOException e) {
122 | e.printStackTrace();
123 | } catch (Exception e) {
124 | e.printStackTrace();
125 | }
126 | new ConnectionTask().execute();
127 |
128 | }
129 | };
130 | }
131 | class ConnectionTask extends AsyncTask {
132 |
133 | protected String doInBackground(String... params) {
134 | String responce = null;
135 | try {
136 |
137 | InputStream input = socket.getInputStream();
138 | int lockSeconds = 10 * 1000;
139 |
140 | long lockThreadCheckpoint = System.currentTimeMillis();
141 | int availableBytes = input.available();
142 | while (availableBytes <= 0 && (System.currentTimeMillis() < lockThreadCheckpoint + lockSeconds)) {
143 | try {
144 | Thread.sleep(10);
145 | } catch (InterruptedException ie) {
146 | ie.printStackTrace();
147 | }
148 | availableBytes = input.available();
149 | }
150 |
151 | byte[] buffer = new byte[availableBytes];
152 | input.read(buffer, 0, availableBytes);
153 | responce = new String(buffer);
154 |
155 | //out.close();
156 | input.close();
157 | socket.close();
158 | } catch (UnknownHostException e) {
159 | e.printStackTrace();
160 | } catch (IOException e) {
161 | e.printStackTrace();
162 | } catch (Exception e) {
163 | e.printStackTrace();
164 | }
165 | return responce;
166 | }
167 |
168 | protected void onPostExecute(String responce) {
169 | if (responce != null) {
170 | tab1.setText(responce + " C");
171 | }
172 | else{
173 |
174 | }
175 |
176 |
177 | }
178 | }
179 |
180 | class ClientThread implements Runnable {
181 |
182 | @Override
183 | public void run() {
184 |
185 | try {
186 | InetAddress serverAddr = InetAddress.getByName(SERVER_IP);
187 |
188 | socket = new Socket(serverAddr, SERVERPORT);
189 |
190 | } catch (UnknownHostException e1) {
191 | e1.printStackTrace();
192 | } catch (IOException e1) {
193 | e1.printStackTrace();
194 | }
195 |
196 | }
197 |
198 | }
199 |
200 | }
--------------------------------------------------------------------------------
/src/main/java/com/mithu/mithunmistry/mithun/HumidityActivity.java:
--------------------------------------------------------------------------------
1 | package com.mithu.mithunmistry.mithun;
2 |
3 | import android.content.Intent;
4 | import android.content.SharedPreferences;
5 | import android.os.AsyncTask;
6 | import android.os.Bundle;
7 | import android.preference.PreferenceManager;
8 | import android.support.design.widget.FloatingActionButton;
9 | import android.support.design.widget.Snackbar;
10 | import android.support.v7.app.AppCompatActivity;
11 | import android.support.v7.widget.Toolbar;
12 | import android.view.View;
13 | import android.widget.TextView;
14 |
15 | import java.io.BufferedWriter;
16 | import java.io.IOException;
17 | import java.io.InputStream;
18 | import java.io.OutputStreamWriter;
19 | import java.io.PrintWriter;
20 | import java.net.InetAddress;
21 | import java.net.Socket;
22 | import java.net.UnknownHostException;
23 | import java.util.Timer;
24 | import java.util.TimerTask;
25 |
26 | public class HumidityActivity extends AppCompatActivity {
27 | Timer timer;
28 | TimerTask timerTask;
29 | String message = "gethumidity";
30 | int SERVERPORT = 6000;
31 | String SERVER_IP = "192.168.1.100";
32 | Socket socket;
33 | Integer x = 1;
34 | Integer ic = 1;
35 | Integer error = -999;
36 | TextView humidity;
37 |
38 | @Override
39 | protected void onCreate(Bundle savedInstanceState) {
40 | super.onCreate(savedInstanceState);
41 | setContentView(R.layout.activity_humidity);
42 | SharedPreferences portip = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
43 | String ipr = portip.getString("IP", "192.168.1.100");
44 | int portr = portip.getInt("Port", 6000);
45 | //Log.d("test", test1);
46 | SERVER_IP = ipr;
47 | SERVERPORT = portr;
48 |
49 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
50 | setSupportActionBar(toolbar);
51 | humidity = (TextView)findViewById(R.id.humidity);
52 | ic = 1;
53 | startTimer();
54 |
55 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
56 | fab.setOnClickListener(new View.OnClickListener() {
57 | @Override
58 | public void onClick(View view) {
59 | Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
60 | .setAction("Action", null);
61 | }
62 | });
63 | }
64 |
65 | @Override
66 | public void onBackPressed() {
67 |
68 | ic = 0;
69 | Intent intent = new Intent(this, ParameterActivity.class);
70 | startActivity(intent);
71 | finish();
72 | }
73 |
74 | public void startTimer() {
75 | //set a new Timer
76 | timer = new Timer();
77 | //initialize the TimerTask's job
78 | initializeTimerTask();
79 | //schedule the timer, after the first 5000ms the TimerTask will run every 10000ms
80 | timer.schedule(timerTask, 100, 4000); //
81 | }
82 |
83 | public void stoptimertask(View v) {
84 | //stop the timer, if it's not already null
85 | if (timer != null) {
86 | timer.cancel();
87 | timer = null;
88 | }
89 | }
90 |
91 |
92 |
93 | public void initializeTimerTask() {
94 | timerTask = new TimerTask() {
95 | public void run() {
96 | //use a handler to run a toast that shows the current timestamp
97 | new Thread(new ClientThread()).start();
98 | try {
99 | String str = message;
100 |
101 | PrintWriter out = new PrintWriter(new BufferedWriter(
102 | new OutputStreamWriter(socket.getOutputStream())), true);
103 | out.println(str);
104 | out.flush();
105 | } catch (UnknownHostException e) {
106 | e.printStackTrace();
107 | } catch (IOException e) {
108 | e.printStackTrace();
109 | } catch (Exception e) {
110 | e.printStackTrace();
111 | }
112 | new ConnectionTask().execute();
113 |
114 | }
115 | };
116 | }
117 | class ConnectionTask extends AsyncTask {
118 |
119 | protected String doInBackground(String... params) {
120 | String responce = null;
121 | try {
122 |
123 | InputStream input = socket.getInputStream();
124 | int lockSeconds = 10 * 1000;
125 |
126 | long lockThreadCheckpoint = System.currentTimeMillis();
127 | int availableBytes = input.available();
128 | while (availableBytes <= 0 && (System.currentTimeMillis() < lockThreadCheckpoint + lockSeconds)) {
129 | try {
130 | Thread.sleep(10);
131 | } catch (InterruptedException ie) {
132 | ie.printStackTrace();
133 | }
134 | availableBytes = input.available();
135 | }
136 |
137 | byte[] buffer = new byte[availableBytes];
138 | input.read(buffer, 0, availableBytes);
139 | responce = new String(buffer);
140 |
141 | //out.close();
142 | input.close();
143 | socket.close();
144 | } catch (UnknownHostException e) {
145 | e.printStackTrace();
146 | } catch (IOException e) {
147 | e.printStackTrace();
148 | } catch (Exception e) {
149 | e.printStackTrace();
150 | }
151 | return responce;
152 | }
153 |
154 | protected void onPostExecute(String responce) {
155 | if(ic.intValue() == x.intValue()) {
156 |
157 | if (responce != null) {
158 | if (responce.equals("thfail")) {
159 | humidity.setText("Humidity sensor failed.");
160 | } else {
161 | humidity.setText(responce + " %");
162 | }
163 |
164 | } else {
165 | message = "gethumidity";
166 | }
167 | }
168 | else{
169 |
170 | }
171 |
172 |
173 | }
174 |
175 |
176 | }
177 |
178 |
179 | class ClientThread implements Runnable {
180 |
181 | @Override
182 | public void run() {
183 | if (ic.intValue() == x.intValue()) {
184 |
185 | try {
186 | InetAddress serverAddr = InetAddress.getByName(SERVER_IP);
187 |
188 | socket = new Socket(serverAddr, SERVERPORT);
189 |
190 | } catch (UnknownHostException e1) {
191 | e1.printStackTrace();
192 | } catch (IOException e1) {
193 | e1.printStackTrace();
194 | }
195 |
196 | }
197 | else{
198 |
199 | }
200 |
201 | }
202 | }
203 |
204 | }
205 |
--------------------------------------------------------------------------------
/src/main/java/com/mithu/mithunmistry/mithun/Main22Activity.java:
--------------------------------------------------------------------------------
1 | package com.mithu.mithunmistry.mithun;
2 |
3 | import java.io.BufferedWriter;
4 | import java.io.IOException;
5 | import java.io.InputStream;
6 | import java.io.OutputStreamWriter;
7 | import java.io.PrintWriter;
8 | import java.net.InetAddress;
9 | import java.net.Socket;
10 | import java.net.UnknownHostException;
11 | import java.util.Timer;
12 | import java.util.TimerTask;
13 |
14 | import android.os.AsyncTask;
15 | import android.os.Bundle;
16 | import android.app.Activity;
17 | import android.view.View;
18 | import android.widget.TextView;
19 |
20 | public class Main22Activity extends Activity {
21 |
22 | private Socket socket;
23 |
24 | private static final int SERVERPORT = 6000;
25 | private static final String SERVER_IP = "192.168.1.100";
26 | TextView risp;
27 | Timer timer;
28 | TimerTask timerTask;
29 | String message = "hello";
30 |
31 | @Override
32 | public void onCreate(Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 | setContentView(R.layout.activity_main22);
35 | risp = (TextView) findViewById(R.id.display);
36 | //new Thread(new ClientThread()).start();
37 | // new ConnectionTask().execute();
38 | startTimer();
39 |
40 |
41 | }
42 |
43 | public void startTimer() {
44 | //set a new Timer
45 | timer = new Timer();
46 | //initialize the TimerTask's job
47 | initializeTimerTask();
48 | //schedule the timer, after the first 5000ms the TimerTask will run every 10000ms
49 | timer.schedule(timerTask, 5000, 3000); //
50 | }
51 | public void stoptimertask(View v) {
52 | //stop the timer, if it's not already null
53 | if (timer != null) {
54 | timer.cancel();
55 | timer = null;
56 | }
57 | }
58 |
59 | public void initializeTimerTask() {
60 | timerTask = new TimerTask() {
61 | public void run() {
62 | //use a handler to run a toast that shows the current timestamp
63 | new Thread(new ClientThread()).start();
64 | try {
65 | String str = message;
66 |
67 | PrintWriter out = new PrintWriter(new BufferedWriter(
68 | new OutputStreamWriter(socket.getOutputStream())), true);
69 | out.println(str);
70 | out.flush();
71 | } catch (UnknownHostException e) {
72 | e.printStackTrace();
73 | } catch (IOException e) {
74 | e.printStackTrace();
75 | } catch (Exception e) {
76 | e.printStackTrace();
77 | }
78 | new ConnectionTask().execute();
79 |
80 | }
81 | };
82 | }
83 |
84 | public void onClick(View view) {
85 | //new ConnectionTask().execute();
86 | new Thread(new ClientThread()).start();
87 | try {
88 | String str = "hello";
89 |
90 | PrintWriter out = new PrintWriter(new BufferedWriter(
91 | new OutputStreamWriter(socket.getOutputStream())), true);
92 | out.println(str);
93 | out.flush();
94 | } catch (UnknownHostException e) {
95 | e.printStackTrace();
96 | } catch (IOException e) {
97 | e.printStackTrace();
98 | } catch (Exception e) {
99 | e.printStackTrace();
100 | }
101 | new ConnectionTask().execute();
102 | }
103 |
104 | public void clear22(View view) {
105 | //new ConnectionTask().execute();
106 | message = "hi";
107 |
108 | // if(risp.getText().equals("success_2")){
109 | // startTimer();
110 | // }
111 | // else{
112 | // clear22(view);
113 | // }
114 |
115 | }
116 |
117 | class ConnectionTask extends AsyncTask {
118 |
119 | protected String doInBackground(String... params) {
120 | String responce = null;
121 | try {
122 |
123 | InputStream input = socket.getInputStream();
124 | int lockSeconds = 10 * 1000;
125 |
126 | long lockThreadCheckpoint = System.currentTimeMillis();
127 | int availableBytes = input.available();
128 | while (availableBytes <= 0 && (System.currentTimeMillis() < lockThreadCheckpoint + lockSeconds)) {
129 | try {
130 | Thread.sleep(10);
131 | } catch (InterruptedException ie) {
132 | ie.printStackTrace();
133 | }
134 | availableBytes = input.available();
135 | }
136 |
137 | byte[] buffer = new byte[availableBytes];
138 | input.read(buffer, 0, availableBytes);
139 | responce = new String(buffer);
140 |
141 | //out.close();
142 | input.close();
143 | socket.close();
144 | } catch (UnknownHostException e) {
145 | e.printStackTrace();
146 | } catch (IOException e) {
147 | e.printStackTrace();
148 | } catch (Exception e) {
149 | e.printStackTrace();
150 | }
151 | return responce;
152 | }
153 |
154 | protected void onPostExecute(String responce) {
155 | risp.setText(responce);
156 | if (responce != null) {
157 | if (responce.equals("success_2")) {
158 | message = "hello";
159 | }
160 | }
161 | //new Thread(new ClientThread()).start();
162 | /*try {
163 | Thread.sleep(100);
164 | } catch (InterruptedException e) {
165 | // TODO Auto-generated catch block
166 | e.printStackTrace();
167 | }*/
168 |
169 | }
170 | }
171 |
172 | class ClientThread implements Runnable {
173 |
174 | @Override
175 | public void run() {
176 |
177 | try {
178 | InetAddress serverAddr = InetAddress.getByName(SERVER_IP);
179 |
180 | socket = new Socket(serverAddr, SERVERPORT);
181 |
182 | } catch (UnknownHostException e1) {
183 | e1.printStackTrace();
184 | } catch (IOException e1) {
185 | e1.printStackTrace();
186 | }
187 |
188 | }
189 |
190 | }
191 | }
--------------------------------------------------------------------------------
/src/main/java/com/mithu/mithunmistry/mithun/experiment2.java:
--------------------------------------------------------------------------------
1 | package com.mithu.mithunmistry.mithun;
2 |
3 | import org.achartengine.GraphicalView;
4 |
5 | import android.app.Activity;
6 | import android.content.Intent;
7 | import android.content.SharedPreferences;
8 | import android.os.AsyncTask;
9 | import android.os.Bundle;
10 | import android.preference.PreferenceManager;
11 | import android.view.View;
12 | import android.view.WindowManager;
13 |
14 | import java.io.BufferedWriter;
15 | import java.io.IOException;
16 | import java.io.InputStream;
17 | import java.io.OutputStreamWriter;
18 | import java.io.PrintWriter;
19 | import java.net.InetAddress;
20 | import java.net.Socket;
21 | import java.net.UnknownHostException;
22 | import java.util.Calendar;
23 | import java.util.Timer;
24 | import java.util.TimerTask;
25 |
26 | public class experiment2 extends Activity {
27 |
28 | private static GraphicalView view;
29 | private LineGraph line = new LineGraph();
30 | private static Thread thread;
31 | Timer timer;
32 | TimerTask timerTask;
33 | int SERVERPORT = 6000;
34 | String SERVER_IP = "192.168.1.100";
35 | Socket socket;
36 | Integer x = 1;
37 | Integer ic = 1;
38 | String message = "graphtemp";
39 | static int c = 30;
40 | Calendar cl;
41 |
42 | /**
43 | * Called when the activity is first created.
44 | */
45 | @Override
46 | public void onCreate(Bundle savedInstanceState) {
47 | super.onCreate(savedInstanceState);
48 | setContentView(R.layout.activity_experiment2);
49 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
50 |
51 | SharedPreferences portip = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
52 | String ipr = portip.getString("IP", "192.168.1.100");
53 | int portr = portip.getInt("Port", 6000);
54 | //Log.d("test", test1);
55 | SERVER_IP = ipr;
56 | SERVERPORT = portr;
57 | ic = 1;
58 | startTimer();
59 |
60 | thread = new Thread() {
61 | public void run() {
62 | for (int i = 0; ; i++) {
63 | try {
64 | Thread.sleep(2000);
65 | } catch (InterruptedException e) {
66 | // TODO Auto-generated catch block
67 | e.printStackTrace();
68 | }
69 | Point p = getdata(i); // We got new data!
70 | line.addNewPoints(p); // Add it to our graph
71 | view.repaint();
72 | }
73 | }
74 | };
75 | thread.start();
76 | }
77 |
78 | @Override
79 | public void onBackPressed() {
80 | ic = 0;
81 | Intent intent = new Intent(this, TemperatureActivity.class);
82 | startActivity(intent);
83 | finish();
84 | }
85 |
86 | @Override
87 | protected void onStart() {
88 | super.onStart();
89 | view = line.getView(this);
90 | setContentView(view);
91 | }
92 | public void startTimer() {
93 | //set a new Timer
94 | timer = new Timer();
95 | //initialize the TimerTask's job
96 | initializeTimerTask();
97 | //schedule the timer, after the first 5000ms the TimerTask will run every 10000ms
98 | timer.schedule(timerTask, 100, 4000); //
99 | }
100 |
101 | public void stoptimertask(View v) {
102 | //stop the timer, if it's not already null
103 | if (timer != null) {
104 | timer.cancel();
105 | timer = null;
106 | }
107 | }
108 |
109 |
110 |
111 | public void initializeTimerTask() {
112 | timerTask = new TimerTask() {
113 | public void run() {
114 | //use a handler to run a toast that shows the current timestamp
115 | new Thread(new ClientThread()).start();
116 | try {
117 | String str = message;
118 |
119 | PrintWriter out = new PrintWriter(new BufferedWriter(
120 | new OutputStreamWriter(socket.getOutputStream())), true);
121 | out.println(str);
122 | out.flush();
123 | } catch (UnknownHostException e) {
124 | e.printStackTrace();
125 | } catch (IOException e) {
126 | e.printStackTrace();
127 | } catch (Exception e) {
128 | e.printStackTrace();
129 | }
130 | new ConnectionTask().execute();
131 |
132 | }
133 | };
134 | }
135 | class ConnectionTask extends AsyncTask {
136 |
137 | protected String doInBackground(String... params) {
138 | String responce = null;
139 | try {
140 |
141 | InputStream input = socket.getInputStream();
142 | int lockSeconds = 10 * 1000;
143 |
144 | long lockThreadCheckpoint = System.currentTimeMillis();
145 | int availableBytes = input.available();
146 | while (availableBytes <= 0 && (System.currentTimeMillis() < lockThreadCheckpoint + lockSeconds)) {
147 | try {
148 | Thread.sleep(10);
149 | } catch (InterruptedException ie) {
150 | ie.printStackTrace();
151 | }
152 | availableBytes = input.available();
153 | }
154 |
155 | byte[] buffer = new byte[availableBytes];
156 | input.read(buffer, 0, availableBytes);
157 | responce = new String(buffer);
158 |
159 | //out.close();
160 | input.close();
161 | socket.close();
162 | } catch (UnknownHostException e) {
163 | e.printStackTrace();
164 | } catch (IOException e) {
165 | e.printStackTrace();
166 | } catch (Exception e) {
167 | e.printStackTrace();
168 | }
169 | return responce;
170 | }
171 |
172 | protected void onPostExecute(String responce) {
173 | if (ic.intValue() == x.intValue()) {
174 |
175 | if (responce != null) {
176 | c = Integer.parseInt(responce);
177 |
178 |
179 | } else {
180 | //c = 30;
181 | //message = "graphtemp";
182 | }
183 |
184 |
185 | }
186 | else{
187 |
188 | }
189 | }
190 |
191 |
192 | }
193 |
194 |
195 | class ClientThread implements Runnable {
196 |
197 | @Override
198 | public void run() {
199 | if (ic.intValue() == x.intValue()) {
200 |
201 | try {
202 | InetAddress serverAddr = InetAddress.getByName(SERVER_IP);
203 |
204 | socket = new Socket(serverAddr, SERVERPORT);
205 |
206 | } catch (UnknownHostException e1) {
207 | e1.printStackTrace();
208 | } catch (IOException e1) {
209 | e1.printStackTrace();
210 | }
211 |
212 | }
213 | else{
214 |
215 | }
216 |
217 | }
218 | }
219 |
220 | public static Point getdata(int x)
221 | {
222 | return new Point(x, c);
223 | }
224 |
225 |
226 | }
--------------------------------------------------------------------------------
/src/main/java/com/mithu/mithunmistry/mithun/TemperatureActivity.java:
--------------------------------------------------------------------------------
1 | package com.mithu.mithunmistry.mithun;
2 |
3 | import android.content.Intent;
4 | import android.content.SharedPreferences;
5 | import android.os.AsyncTask;
6 | import android.os.Bundle;
7 | import android.preference.PreferenceManager;
8 | import android.support.design.widget.FloatingActionButton;
9 | import android.support.design.widget.Snackbar;
10 | import android.support.v7.app.AppCompatActivity;
11 | import android.support.v7.widget.Toolbar;
12 | import android.view.View;
13 | import android.widget.Button;
14 | import android.widget.TextView;
15 |
16 | import java.io.BufferedWriter;
17 | import java.io.IOException;
18 | import java.io.InputStream;
19 | import java.io.OutputStreamWriter;
20 | import java.io.PrintWriter;
21 | import java.net.InetAddress;
22 | import java.net.Socket;
23 | import java.net.UnknownHostException;
24 | import java.util.Timer;
25 | import java.util.TimerTask;
26 |
27 | public class TemperatureActivity extends AppCompatActivity {
28 | Timer timer;
29 | TimerTask timerTask;
30 | String message = "gettemp";
31 | int SERVERPORT = 6000;
32 | String SERVER_IP = "192.168.1.100";
33 | Socket socket;
34 | Integer x = 1;
35 | Integer ic = 1;
36 | Integer error = -1000;
37 | TextView celcius, farenheit;
38 | Button tlive;
39 |
40 | @Override
41 | protected void onCreate(Bundle savedInstanceState) {
42 | super.onCreate(savedInstanceState);
43 | setContentView(R.layout.activity_temperature);
44 | SharedPreferences portip = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
45 | String ipr = portip.getString("IP", "192.168.1.100");
46 | int portr = portip.getInt("Port", 6000);
47 | //Log.d("test", test1);
48 | SERVER_IP = ipr;
49 | SERVERPORT = portr;
50 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
51 | setSupportActionBar(toolbar);
52 | celcius = (TextView)findViewById(R.id.tempCelcius);
53 | farenheit = (TextView)findViewById(R.id.tempFarenheit);
54 | tlive = (Button)findViewById(R.id.tempLivePlot);
55 | ic = 1;
56 | startTimer();
57 |
58 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
59 | fab.setOnClickListener(new View.OnClickListener() {
60 | @Override
61 | public void onClick(View view) {
62 | Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
63 | .setAction("Action", null).show();
64 | }
65 | });
66 | }
67 |
68 | @Override
69 | public void onBackPressed() {
70 | ic = 0;
71 | Intent intent = new Intent(this, ParameterActivity.class);
72 | startActivity(intent);
73 | finish();
74 | }
75 |
76 | public void tLivePlotting(View view){
77 | Intent intent = new Intent(this, experiment2.class);
78 | startActivity(intent);
79 | }
80 |
81 | public void startTimer() {
82 | //set a new Timer
83 | timer = new Timer();
84 | //initialize the TimerTask's job
85 | initializeTimerTask();
86 | //schedule the timer, after the first 5000ms the TimerTask will run every 10000ms
87 | timer.schedule(timerTask, 100, 4000); //
88 | }
89 |
90 | public void stoptimertask(View v) {
91 | //stop the timer, if it's not already null
92 | if (timer != null) {
93 | timer.cancel();
94 | timer = null;
95 | }
96 | }
97 |
98 |
99 |
100 | public void initializeTimerTask() {
101 | timerTask = new TimerTask() {
102 | public void run() {
103 | //use a handler to run a toast that shows the current timestamp
104 | new Thread(new ClientThread()).start();
105 | try {
106 | String str = message;
107 |
108 | PrintWriter out = new PrintWriter(new BufferedWriter(
109 | new OutputStreamWriter(socket.getOutputStream())), true);
110 | out.println(str);
111 | out.flush();
112 | } catch (UnknownHostException e) {
113 | e.printStackTrace();
114 | } catch (IOException e) {
115 | e.printStackTrace();
116 | } catch (Exception e) {
117 | e.printStackTrace();
118 | }
119 | new ConnectionTask().execute();
120 |
121 | }
122 | };
123 | }
124 | class ConnectionTask extends AsyncTask {
125 |
126 | protected String doInBackground(String... params) {
127 | String responce = null;
128 | try {
129 |
130 | InputStream input = socket.getInputStream();
131 | int lockSeconds = 10 * 1000;
132 |
133 | long lockThreadCheckpoint = System.currentTimeMillis();
134 | int availableBytes = input.available();
135 | while (availableBytes <= 0 && (System.currentTimeMillis() < lockThreadCheckpoint + lockSeconds)) {
136 | try {
137 | Thread.sleep(10);
138 | } catch (InterruptedException ie) {
139 | ie.printStackTrace();
140 | }
141 | availableBytes = input.available();
142 | }
143 |
144 | byte[] buffer = new byte[availableBytes];
145 | input.read(buffer, 0, availableBytes);
146 | responce = new String(buffer);
147 |
148 | //out.close();
149 | input.close();
150 | socket.close();
151 | } catch (UnknownHostException e) {
152 | e.printStackTrace();
153 | } catch (IOException e) {
154 | e.printStackTrace();
155 | } catch (Exception e) {
156 | e.printStackTrace();
157 | }
158 | return responce;
159 | }
160 |
161 | protected void onPostExecute(String responce) {
162 | if (ic.intValue() == x.intValue()) {
163 |
164 | if (responce != null) {
165 | if (responce.equals("thfail")) {
166 | celcius.setText("Temperature sensor failed.");
167 | farenheit.setText("Please Fix it!");
168 | tlive.setVisibility(View.GONE);
169 | } else {
170 | celcius.setText(responce + " °C");
171 | float c = Float.parseFloat(responce);
172 | float faren = ((c * 9 / 5) + 32);
173 | String fh = Float.toString(faren);
174 | farenheit.setText(fh + " °F");
175 | tlive.setVisibility(View.VISIBLE);
176 | }
177 |
178 | } else {
179 | message = "gettemp";
180 | }
181 |
182 |
183 | }
184 | else{
185 |
186 | }
187 | }
188 |
189 |
190 | }
191 |
192 |
193 | class ClientThread implements Runnable {
194 |
195 | @Override
196 | public void run() {
197 | if (ic.intValue() == x.intValue()) {
198 |
199 | try {
200 | InetAddress serverAddr = InetAddress.getByName(SERVER_IP);
201 |
202 | socket = new Socket(serverAddr, SERVERPORT);
203 |
204 | } catch (UnknownHostException e1) {
205 | e1.printStackTrace();
206 | } catch (IOException e1) {
207 | e1.printStackTrace();
208 | }
209 |
210 | }
211 | else{
212 |
213 | }
214 |
215 | }
216 | }
217 |
218 |
219 | }
220 |
--------------------------------------------------------------------------------
/src/main/java/com/mithu/mithunmistry/mithun/brightness_activity.java:
--------------------------------------------------------------------------------
1 | package com.mithu.mithunmistry.mithun;
2 |
3 | import android.content.Intent;
4 | import android.content.SharedPreferences;
5 | import android.os.AsyncTask;
6 | import android.os.Handler;
7 | import android.preference.PreferenceManager;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.os.Bundle;
10 | import android.view.View;
11 | import android.widget.ProgressBar;
12 | import android.widget.SeekBar;
13 | import android.widget.TextView;
14 |
15 | import java.io.BufferedWriter;
16 | import java.io.IOException;
17 | import java.io.InputStream;
18 | import java.io.OutputStreamWriter;
19 | import java.io.PrintWriter;
20 | import java.net.InetAddress;
21 | import java.net.Socket;
22 | import java.net.UnknownHostException;
23 | import java.util.Timer;
24 | import java.util.TimerTask;
25 |
26 | public class brightness_activity extends AppCompatActivity {
27 | SeekBar seekBar2;
28 | TextView brightness_display;
29 | Integer percentage_display;
30 | ProgressBar progressBar;
31 | Socket socket;
32 | Integer x = 1;
33 | private int i = 0;
34 | Timer timer;
35 | TimerTask timerTask;
36 | String message = "1";
37 | int SERVERPORT = 6000;
38 | String SERVER_IP = "192.168.1.100";
39 | Integer ic = 1;
40 | Integer progressvalue;
41 |
42 | @Override
43 | protected void onCreate(Bundle savedInstanceState) {
44 | super.onCreate(savedInstanceState);
45 | setContentView(R.layout.activity_brightness_activity);
46 | seekBar2 = (SeekBar)findViewById(R.id.seekBar);
47 | brightness_display = (TextView)findViewById(R.id.brightness_text);
48 | progressBar = (ProgressBar)findViewById(R.id.progressBar2);
49 | ic = 1;
50 | SharedPreferences portip = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
51 | String ipr = portip.getString("IP", "192.168.1.100");
52 | int portr = portip.getInt("Port", 6000);
53 | //Log.d("test", test1);
54 | SERVER_IP = ipr;
55 | SERVERPORT = portr;
56 |
57 | startTimer();
58 | if(i == 0) {
59 | progressBar.setVisibility(View.VISIBLE);
60 | progressBar.setMax(3);
61 | }
62 | else if (i< progressBar.getMax()){
63 | progressBar.setProgress(i);
64 | i = i + 1;
65 | }
66 | seekBar2.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
67 | @Override
68 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
69 | progressvalue = progress;
70 | percentage_display = (progress / 9);
71 | brightness_display.setText(String.valueOf(percentage_display) + "%");
72 | }
73 |
74 | @Override
75 | public void onStartTrackingTouch(SeekBar seekBar) {
76 |
77 | }
78 |
79 | @Override
80 | public void onStopTrackingTouch(SeekBar seekBar) {
81 | message = Integer.toString(progressvalue);
82 |
83 | }
84 | });
85 | }
86 | @Override
87 | public void onBackPressed() {
88 | message = "lauto";
89 | if(i == 0) {
90 | progressBar.setVisibility(View.VISIBLE);
91 | seekBar2.setVisibility(View.GONE);
92 | progressBar.setMax(3);
93 | }
94 | else if (i< progressBar.getMax()){
95 | progressBar.setProgress(i);
96 | i = i + 1;
97 | }
98 | Handler handler = new Handler();
99 | handler.postDelayed(new Runnable() {
100 | @Override
101 | public void run() {
102 | // do something
103 | ic = 0;
104 | Intent intent = new Intent(getApplicationContext(), Main2Activity.class);
105 | startActivity(intent);
106 | finish();
107 | }
108 | }, 4000);
109 |
110 | }
111 |
112 | public void startTimer() {
113 | //set a new Timer
114 | timer = new Timer();
115 | //initialize the TimerTask's job
116 | initializeTimerTask();
117 | //schedule the timer, after the first 5000ms the TimerTask will run every 10000ms
118 | timer.schedule(timerTask, 100, 2000); //
119 | }
120 |
121 | public void stoptimertask(View v) {
122 | //stop the timer, if it's not already null
123 | if (timer != null) {
124 | timer.cancel();
125 | timer = null;
126 | }
127 | }
128 |
129 | public void initializeTimerTask() {
130 | timerTask = new TimerTask() {
131 | public void run() {
132 | //use a handler to run a toast that shows the current timestamp
133 | new Thread(new ClientThread()).start();
134 | try {
135 | String str = message;
136 |
137 | PrintWriter out = new PrintWriter(new BufferedWriter(
138 | new OutputStreamWriter(socket.getOutputStream())), true);
139 | out.println(str);
140 | out.flush();
141 | } catch (UnknownHostException e) {
142 | e.printStackTrace();
143 | } catch (IOException e) {
144 | e.printStackTrace();
145 | } catch (Exception e) {
146 | e.printStackTrace();
147 | }
148 | new ConnectionTask().execute();
149 |
150 | }
151 | };
152 | }
153 | class ConnectionTask extends AsyncTask {
154 |
155 | protected String doInBackground(String... params) {
156 | String responce = null;
157 | try {
158 |
159 | InputStream input = socket.getInputStream();
160 | int lockSeconds = 10 * 1000;
161 |
162 | long lockThreadCheckpoint = System.currentTimeMillis();
163 | int availableBytes = input.available();
164 | while (availableBytes <= 0 && (System.currentTimeMillis() < lockThreadCheckpoint + lockSeconds)) {
165 | try {
166 | Thread.sleep(10);
167 | } catch (InterruptedException ie) {
168 | ie.printStackTrace();
169 | }
170 | availableBytes = input.available();
171 | }
172 |
173 | byte[] buffer = new byte[availableBytes];
174 | input.read(buffer, 0, availableBytes);
175 | responce = new String(buffer);
176 |
177 | //out.close();
178 | input.close();
179 | socket.close();
180 | } catch (UnknownHostException e) {
181 | e.printStackTrace();
182 | } catch (IOException e) {
183 | e.printStackTrace();
184 | } catch (Exception e) {
185 | e.printStackTrace();
186 | }
187 | return responce;
188 | }
189 |
190 | protected void onPostExecute(String responce) {
191 | if (responce != null) {
192 | if(responce.equals("lmanual")){
193 | progressBar.setProgress(0);
194 | //i = 0;
195 |
196 | progressBar.setVisibility(View.GONE);
197 | i = 0;
198 | seekBar2.setVisibility(View.VISIBLE);
199 | }
200 |
201 |
202 | }
203 | else{
204 | //message = "hello";
205 |
206 | }
207 |
208 |
209 | }
210 | }
211 |
212 | class ClientThread implements Runnable {
213 |
214 | @Override
215 | public void run() {
216 | if (ic.intValue() == x.intValue()) {
217 |
218 | try {
219 | InetAddress serverAddr = InetAddress.getByName(SERVER_IP);
220 |
221 | socket = new Socket(serverAddr, SERVERPORT);
222 |
223 | } catch (UnknownHostException e1) {
224 | e1.printStackTrace();
225 | } catch (IOException e1) {
226 | e1.printStackTrace();
227 | }
228 |
229 | }
230 | else{
231 |
232 | }
233 |
234 | }
235 | }
236 | }
237 |
--------------------------------------------------------------------------------
/src/main/res/layout/content_raspberry_pi.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
16 |
17 |
20 |
21 |
29 |
30 |
31 |
32 |
35 |
36 |
45 |
46 |
47 |
48 |
51 |
52 |
59 |
60 |
61 |
64 |
65 |
73 |
74 |
75 |
76 |
79 |
80 |
89 |
90 |
91 |
94 |
95 |
103 |
104 |
105 |
106 |
109 |
110 |
119 |
120 |
121 |
124 |
125 |
133 |
134 |
135 |
136 |
139 |
140 |
149 |
150 |
151 |
154 |
155 |
162 |
163 |
164 |
167 |
168 |
169 |
170 |
173 |
174 |
175 |
176 |
179 |
180 |
181 |
182 |
185 |
186 |
187 |
188 |
191 |
192 |
198 |
199 |
200 |
203 |
204 |
213 |
214 |
215 |
218 |
219 |
220 |
221 |
222 |
--------------------------------------------------------------------------------