├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ruler96.png
│ │ │ │ ├── asteroid104.png
│ │ │ │ ├── gyroscope96.png
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── pressure104.png
│ │ │ │ ├── temperature104.png
│ │ │ │ ├── define_location104.png
│ │ │ │ ├── light_automation_filled100.png
│ │ │ │ └── protect_from_magnetic_field104.png
│ │ │ ├── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── styles.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── drawables.xml
│ │ │ ├── drawable
│ │ │ │ ├── side_nav_bar.xml
│ │ │ │ └── ic_warning_black_24dp.xml
│ │ │ ├── drawable-v21
│ │ │ │ ├── ic_menu_send.xml
│ │ │ │ ├── ic_menu_slideshow.xml
│ │ │ │ ├── ic_menu_gallery.xml
│ │ │ │ ├── ic_menu_manage.xml
│ │ │ │ ├── ic_menu_camera.xml
│ │ │ │ └── ic_menu_share.xml
│ │ │ ├── layout
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── activity_sensor.xml
│ │ │ │ ├── content_preview.xml
│ │ │ │ ├── app_bar_preview.xml
│ │ │ │ ├── edit_setip.xml
│ │ │ │ ├── activity_preview.xml
│ │ │ │ ├── nav_header_main2.xml
│ │ │ │ └── sensor_item.xml
│ │ │ ├── values-v21
│ │ │ │ └── styles.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── menu
│ │ │ │ └── activity_preview_drawer.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── onlylemi
│ │ │ │ └── android
│ │ │ │ ├── sense
│ │ │ │ ├── SensorInfo.java
│ │ │ │ ├── SensorListAdapter.java
│ │ │ │ └── SensorActivity.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ ├── capture
│ │ │ │ ├── SendDataThread.java
│ │ │ │ ├── ColorCrosshairView.java
│ │ │ │ ├── PreviewSurface.java
│ │ │ │ ├── CameraSurface.java
│ │ │ │ └── PreviewActivity.java
│ │ │ │ └── BaseActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── onlylemi
│ │ │ └── android
│ │ │ └── capture
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── onlylemi
│ │ └── android
│ │ └── capture
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── .gitignore
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── README.md
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea
5 | .DS_Store
6 | /build
7 | /captures
8 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/onlylemi/AndroidCapture/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ruler96.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/onlylemi/AndroidCapture/HEAD/app/src/main/res/mipmap-hdpi/ruler96.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/asteroid104.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/onlylemi/AndroidCapture/HEAD/app/src/main/res/mipmap-hdpi/asteroid104.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/gyroscope96.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/onlylemi/AndroidCapture/HEAD/app/src/main/res/mipmap-hdpi/gyroscope96.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/onlylemi/AndroidCapture/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/pressure104.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/onlylemi/AndroidCapture/HEAD/app/src/main/res/mipmap-hdpi/pressure104.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/temperature104.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/onlylemi/AndroidCapture/HEAD/app/src/main/res/mipmap-hdpi/temperature104.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/define_location104.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/onlylemi/AndroidCapture/HEAD/app/src/main/res/mipmap-hdpi/define_location104.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/light_automation_filled100.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/onlylemi/AndroidCapture/HEAD/app/src/main/res/mipmap-hdpi/light_automation_filled100.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/protect_from_magnetic_field104.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/onlylemi/AndroidCapture/HEAD/app/src/main/res/mipmap-hdpi/protect_from_magnetic_field104.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Mar 28 07:50:19 CST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #00000000
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/side_nav_bar.xml:
--------------------------------------------------------------------------------
1 |
3 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v21/ic_menu_send.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 | >
2 |
3 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_warning_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/test/java/com/onlylemi/android/capture/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.onlylemi.android.capture;
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 | }
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/onlylemi/android/capture/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.onlylemi.android.capture;
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 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 16dp
6 |
7 | 16dp
8 | 160dp
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v21/ic_menu_slideshow.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v21/ic_menu_gallery.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v21/ic_menu_manage.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_sensor.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v21/ic_menu_camera.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/app/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 E:\eclipse\sdk\android-sdk-windows/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 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v21/ic_menu_share.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_preview.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/java/com/onlylemi/android/sense/SensorInfo.java:
--------------------------------------------------------------------------------
1 | package com.onlylemi.android.sense;
2 |
3 | /**
4 | * Created by only乐秘 on 2015-12-30.
5 | */
6 | public class SensorInfo {
7 |
8 | private String name;
9 | private int imageId;
10 |
11 | public String getName() {
12 | return name;
13 | }
14 |
15 | public void setName(String name) {
16 | this.name = name;
17 | }
18 |
19 | public int getImageId() {
20 | return imageId;
21 | }
22 |
23 | public void setImageId(int imageId) {
24 | this.imageId = imageId;
25 | }
26 |
27 | @Override
28 | public String toString() {
29 | return "SensorInfo{" +
30 | "name='" + name + '\'' +
31 | ", imageId=" + imageId +
32 | '}';
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/app_bar_preview.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.1"
6 |
7 | defaultConfig {
8 | applicationId "com.onlylemi.android.capture"
9 | minSdkVersion 15
10 | targetSdkVersion 23
11 | versionCode 2
12 | versionName "2.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | compile 'com.android.support:appcompat-v7:23.0.1'
25 | compile 'com.android.support:design:23.0.1'
26 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
27 | testCompile 'junit:junit:4.12'
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/edit_setip.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_preview.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_preview_drawer.xml:
--------------------------------------------------------------------------------
1 |
2 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AndroidCapture
3 | Settings
4 | Main2Activity
5 | Android Sensor
6 |
7 | Open navigation drawer
8 | Close navigation drawer
9 |
10 |
11 |
12 | - ACCELEROMETER SENSOR
13 |
14 | - LIGHT SENSOR
15 |
16 | - ORIENTATION SENSOR
17 |
18 | - PROXIMITY SENSOR
19 |
20 | - TEMPERATURE SENSOR
21 |
22 | - PRESSURE SENSOR
23 |
24 | - GYROSCOPE SENSOR
25 |
26 | - MAGNETIC FIELD SENSOR
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/values/drawables.xml:
--------------------------------------------------------------------------------
1 |
2 | - @android:drawable/ic_menu_camera
3 | - @android:drawable/ic_menu_gallery
4 | - @android:drawable/ic_menu_slideshow
5 | - @android:drawable/ic_menu_manage
6 | - @android:drawable/ic_menu_share
7 | - @android:drawable/ic_menu_send
8 |
9 |
10 | - @mipmap/asteroid104
11 | - @mipmap/light_automation_filled100
12 | - @mipmap/define_location104
13 | - @mipmap/ruler96
14 | - @mipmap/temperature104
15 | - @mipmap/pressure104
16 | - @mipmap/gyroscope96
17 | - @mipmap/protect_from_magnetic_field104
18 |
19 |
20 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AndroidCapture
2 | This is a android app, it's a client for my **processing library** named **processing-android-capture**
3 |
4 | **android app豌豆荚下载地址:** (http://www.wandoujia.com/apps/com.onlylemi.android.capture)
5 |
6 | **processing-android-capture:** [https://github.com/onlylemi/processing-android-capture](https://github.com/onlylemi/processing-android-capture)
7 |
8 | This library tries to transfer data between [Processing](https://processing.org) and [Android](https://android.com). I make a android app to capture the real-time video from "Android camera" through the socket to the server (processing server) with `WiFi`. The users use this lib to get phone camera capture in processing, then can do image processing. And currently support read the data of android sensor.
9 |
10 | if there is a problem, please contact me or new a issues.
11 |
12 | 
13 |
14 | 
15 |
16 | 
17 |
18 | 
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/nav_header_main2.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
18 |
19 |
24 |
25 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/sensor_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
15 |
16 |
25 |
26 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/java/com/onlylemi/android/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.onlylemi.android;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 |
6 | import com.onlylemi.android.capture.PreviewActivity;
7 | import com.onlylemi.android.capture.R;
8 |
9 | public class MainActivity extends BaseActivity {
10 |
11 | @Override
12 | protected void onCreate(Bundle savedInstanceState) {
13 | super.onCreate(savedInstanceState);
14 | setContentView(R.layout.activity_main);
15 | }
16 |
17 | @Override
18 | protected void onResume() {
19 | super.onResume();
20 | if (isGrantedAllPermission()) {
21 | startPreview();
22 | }
23 | }
24 |
25 | @Override
26 | protected String[] getNeedPermissions() {
27 | return new String[]{
28 | "android.permission.INTERNET",
29 | "android.permission.CAMERA"
30 | };
31 | }
32 |
33 | @Override
34 | protected String getDialogTipsPart() {
35 | return "CAMERA";
36 | }
37 |
38 | @Override
39 | protected void permissionGrantedSuccess() {
40 | super.permissionGrantedSuccess();
41 | startPreview();
42 | }
43 |
44 | private void startPreview() {
45 | Intent intent = new Intent();
46 | intent.setClass(this, PreviewActivity.class);
47 | startActivity(intent);
48 | finish();
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
18 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
31 |
32 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/onlylemi/android/capture/SendDataThread.java:
--------------------------------------------------------------------------------
1 | package com.onlylemi.android.capture;
2 |
3 | import java.io.ByteArrayInputStream;
4 | import java.io.ByteArrayOutputStream;
5 | import java.io.IOException;
6 | import java.io.OutputStream;
7 | import java.net.Socket;
8 |
9 | public class SendDataThread extends Thread {
10 |
11 | public final static String TAG = "SendDataThread:";
12 |
13 | private byte[] byteBuffer = new byte[1024];
14 | private OutputStream outsocket;
15 | private ByteArrayOutputStream myoutputstream;
16 | private String ipname;
17 | private int port;
18 |
19 | public SendDataThread(ByteArrayOutputStream myoutputstream, String ipname, int port) {
20 | this.myoutputstream = myoutputstream;
21 | this.ipname = ipname;
22 | this.port = port;
23 |
24 | try {
25 | myoutputstream.close();
26 | } catch (IOException e) {
27 | e.printStackTrace();
28 | }
29 | }
30 |
31 | public void run() {
32 | try {
33 | // send image data by socket
34 | if (!"".equals(ipname) && null != ipname) {
35 | Socket tempSocket = new Socket(ipname, port);
36 | outsocket = tempSocket.getOutputStream();
37 | ByteArrayInputStream inputstream = new ByteArrayInputStream(
38 | myoutputstream.toByteArray());
39 | int amount;
40 | while ((amount = inputstream.read(byteBuffer)) != -1) {
41 | outsocket.write(byteBuffer, 0, amount);
42 | }
43 | myoutputstream.flush();
44 | myoutputstream.close();
45 | tempSocket.close();
46 | }
47 | } catch (IOException e) {
48 | e.printStackTrace();
49 | }
50 | }
51 |
52 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/onlylemi/android/capture/ColorCrosshairView.java:
--------------------------------------------------------------------------------
1 | package com.onlylemi.android.capture;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Paint;
6 | import android.graphics.Path;
7 | import android.util.AttributeSet;
8 | import android.view.View;
9 |
10 | public class ColorCrosshairView extends View {
11 |
12 | private final static String TAG = "ColorCrosshairView:";
13 |
14 | private Paint paint;
15 | private Path path;
16 |
17 | public ColorCrosshairView(Context paramContext, AttributeSet paramAttributeSet) {
18 | super(paramContext, paramAttributeSet);
19 | initPaint();
20 | }
21 |
22 | private void initPaint() {
23 | paint = new Paint();
24 | paint.setColor(0);
25 | paint.setStyle(Paint.Style.FILL_AND_STROKE);
26 | paint.setStrokeWidth(2.0F);
27 | paint.setAntiAlias(true);
28 | paint.setStrokeCap(Paint.Cap.BUTT);
29 | paint.setDither(false);
30 | }
31 |
32 | private void updatePath(float paramFloat1, float paramFloat2) {
33 | float f1 = paramFloat1 / 2.0F;
34 | float f2 = paramFloat2 / 2.0F;
35 | float f3 = paramFloat1 / 2.0F - 20.0F - 4.0F;
36 | float f4 = paramFloat1 / 2.0F - 4.0F;
37 | path = new Path();
38 | path.addCircle(f1, f2, f3, Path.Direction.CCW);
39 | path.addCircle(f1, f2, f4, Path.Direction.CW);
40 | path.moveTo(f1, 2.0F * 4.0F);
41 | path.lineTo(f1, f2 - 1.0F);
42 | path.moveTo(paramFloat1 - 2.0F * 4.0F, f2);
43 | path.lineTo(f1 + 1.0F, f2);
44 | }
45 |
46 | public void draw(Canvas paramCanvas) {
47 | super.draw(paramCanvas);
48 | paramCanvas.drawPath(path, paint);
49 | }
50 |
51 | protected void onSizeChanged(int paramInt1, int paramInt2, int paramInt3, int paramInt4) {
52 | super.onSizeChanged(paramInt1, paramInt2, paramInt3, paramInt4);
53 | updatePath(paramInt1, paramInt2);
54 | }
55 |
56 | public void setColor(int paramInt) {
57 | paint.setColor(paramInt);
58 | invalidate();
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/java/com/onlylemi/android/capture/PreviewSurface.java:
--------------------------------------------------------------------------------
1 | package com.onlylemi.android.capture;
2 |
3 | import java.io.ByteArrayInputStream;
4 | import java.io.ByteArrayOutputStream;
5 |
6 | import android.content.Context;
7 | import android.graphics.BitmapFactory;
8 | import android.graphics.ImageFormat;
9 | import android.graphics.Rect;
10 | import android.graphics.YuvImage;
11 | import android.hardware.Camera;
12 | import android.hardware.Camera.Size;
13 | import android.util.AttributeSet;
14 | import android.util.Log;
15 | import android.view.SurfaceHolder;
16 |
17 |
18 | public class PreviewSurface extends CameraSurface implements
19 | Camera.PreviewCallback {
20 |
21 | private static final String TAG = "PreviewSurface:";
22 |
23 | private String ipname = "";
24 | private ColorListener listener;
25 |
26 | public PreviewSurface(Context paramContext, AttributeSet paramAttributeSet) {
27 | super(paramContext, paramAttributeSet);
28 | }
29 |
30 | public void onPreviewFrame(byte[] paramArrayOfByte, Camera paramCamera) {
31 | Size size = paramCamera.getParameters().getPreviewSize();
32 | // use "image.compressToJpeg()" to change image data format from "YUV" to "jpg"
33 | YuvImage image = new YuvImage(paramArrayOfByte, ImageFormat.NV21,
34 | size.width, size.height, null);
35 | ByteArrayOutputStream outstream = new ByteArrayOutputStream();
36 |
37 | try {
38 | if (image != null) {
39 | image.compressToJpeg(new Rect(0, 0, size.width, size.height),
40 | 80, outstream);
41 | outstream.flush();
42 | //start thread to send image data
43 | Thread th = new SendDataThread(outstream, ipname, 6000);
44 | th.start();
45 | }
46 | } catch (Exception ex) {
47 | Log.e(TAG, "Error:" + ex.getMessage());
48 | }
49 |
50 | if (listener != null) {
51 | int color = BitmapFactory.decodeStream(new ByteArrayInputStream(outstream.toByteArray
52 | ())).getPixel(size.width / 2, size.height / 2);
53 | listener.onColor(color);
54 | }
55 |
56 | }
57 |
58 | public void surfaceCreated(SurfaceHolder paramSurfaceHolder) {
59 | super.surfaceCreated(paramSurfaceHolder);
60 | this.camera.setPreviewCallback(this);
61 | }
62 |
63 | public void surfaceDestroyed(SurfaceHolder paramSurfaceHolder) {
64 | this.camera.setPreviewCallback(null);
65 | super.surfaceDestroyed(paramSurfaceHolder);
66 | }
67 |
68 | public void setIP(String ipname) {
69 | this.ipname = ipname;
70 | }
71 |
72 |
73 | public void setColorListener(ColorListener listener) {
74 | this.listener = listener;
75 | }
76 |
77 | public interface ColorListener {
78 | void onColor(int color);
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/app/src/main/java/com/onlylemi/android/capture/CameraSurface.java:
--------------------------------------------------------------------------------
1 | package com.onlylemi.android.capture;
2 |
3 | import android.content.Context;
4 | import android.hardware.Camera;
5 | import android.util.AttributeSet;
6 | import android.util.Log;
7 | import android.view.SurfaceHolder;
8 | import android.view.SurfaceView;
9 |
10 | import java.io.IOException;
11 | import java.util.Iterator;
12 |
13 | public class CameraSurface extends SurfaceView implements SurfaceHolder.Callback {
14 |
15 | private static final String TAG = "CameraSurface:";
16 | public Camera camera;
17 | protected SurfaceHolder holder = getHolder();
18 | private boolean previewing = false;
19 |
20 | public CameraSurface(Context paramContext, AttributeSet paramAttributeSet) {
21 | super(paramContext, paramAttributeSet);
22 | holder.setType(3);
23 | holder.addCallback(this);
24 | setKeepScreenOn(true);
25 | }
26 |
27 | private void setPreferredFormat(Camera.Parameters paramParameters,
28 | int paramInt) {
29 | Iterator localIterator = paramParameters
30 | .getSupportedPreviewFormats().iterator();
31 | while (true) {
32 | if (!localIterator.hasNext())
33 | return;
34 | if (((Integer) localIterator.next()).intValue() == paramInt) {
35 | paramParameters.setPreviewFormat(paramInt);
36 | }
37 | }
38 | }
39 |
40 | private void setPreferredSize(Camera.Parameters paramParameters,
41 | int paramInt1, int paramInt2) {
42 | Iterator localIterator = paramParameters.getSupportedPreviewSizes()
43 | .iterator();
44 | while (true) {
45 | if (!localIterator.hasNext())
46 | return;
47 | Camera.Size localSize = (Camera.Size) localIterator.next();
48 | if ((localSize.width == paramInt1)
49 | && (localSize.height == paramInt2))
50 | paramParameters.setPreviewSize(paramInt1, paramInt2);
51 | }
52 | }
53 |
54 | public void surfaceChanged(SurfaceHolder paramSurfaceHolder, int paramInt1,
55 | int paramInt2, int paramInt3) {
56 | if (camera == null)
57 | return;
58 | if (previewing)
59 | camera.stopPreview();
60 | Camera.Parameters localParameters = camera.getParameters();
61 | setPreferredSize(localParameters, paramInt2, paramInt3);
62 | setPreferredFormat(localParameters, paramInt1);
63 | camera.setParameters(localParameters);
64 | camera.startPreview();
65 | previewing = true;
66 | }
67 |
68 | public void surfaceCreated(SurfaceHolder paramSurfaceHolder) {
69 | try {
70 | camera = Camera.open();
71 | camera.setPreviewDisplay(paramSurfaceHolder);
72 | return;
73 | } catch (IOException localIOException) {
74 | Log.e("CameraSurface", "Error setting preview display.");
75 | camera.release();
76 | camera = null;
77 | }
78 | }
79 |
80 | public void surfaceDestroyed(SurfaceHolder paramSurfaceHolder) {
81 | if (camera != null) {
82 | if (previewing) {
83 | camera.stopPreview();
84 | }
85 | previewing = false;
86 | camera.release();
87 | camera = null;
88 | }
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/app/src/main/java/com/onlylemi/android/sense/SensorListAdapter.java:
--------------------------------------------------------------------------------
1 | package com.onlylemi.android.sense;
2 |
3 | import android.hardware.Sensor;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 | import android.widget.BaseAdapter;
7 | import android.widget.CompoundButton;
8 | import android.widget.ImageView;
9 | import android.widget.Switch;
10 | import android.widget.TextView;
11 | import android.widget.Toast;
12 |
13 | import com.onlylemi.android.capture.R;
14 |
15 | import java.util.List;
16 |
17 | /**
18 | * Created by only乐秘 on 2015-12-29.
19 | */
20 | public class SensorListAdapter extends BaseAdapter {
21 |
22 | public final static String TAG = "SensorListAdapter";
23 | public List list;
24 |
25 | private SensorActivity context;
26 |
27 | public SensorListAdapter(SensorActivity context, List list) {
28 | this.context = context;
29 | this.list = list;
30 | }
31 |
32 | @Override
33 | public int getCount() {
34 | return list.size();
35 | }
36 |
37 | @Override
38 | public Object getItem(int i) {
39 | return list.get(i);
40 | }
41 |
42 | @Override
43 | public long getItemId(int i) {
44 | return i;
45 | }
46 |
47 | @Override
48 | public View getView(int i, View view, ViewGroup viewGroup) {
49 | ViewHolder holder = null;
50 |
51 | if (view == null) {
52 | holder = new ViewHolder();
53 | view = View.inflate(context, R.layout.sensor_item, null);
54 |
55 | holder.sensorImageView = (ImageView) view.findViewById(R.id.senso_image);
56 | holder.sensorNameView = (TextView) view.findViewById(R.id.sensor_name);
57 | holder.sensorSwitch = (Switch) view.findViewById(R.id.sensor_switch);
58 |
59 | view.setTag(holder);
60 | } else {
61 | holder = (ViewHolder) view.getTag();
62 | }
63 |
64 | holder.sensorNameView.setText(list.get(i).getName());
65 | holder.sensorImageView.setImageResource(list.get(i).getImageId());
66 |
67 | final int index = i;
68 | final ViewHolder finalHolder = holder;
69 | holder.sensorSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener
70 | () {
71 | @Override
72 | public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
73 |
74 | int j;
75 | for (j = 0; j < context.getSensors().size(); j++) {
76 | if (context.getSensors().get(j).getType() == SensorActivity
77 | .TYPE_SENSORS[index]) {
78 | if (b) {
79 | Toast.makeText(context, list.get(index).getName() + " ON", Toast
80 | .LENGTH_SHORT)
81 | .show();
82 | context.registerListener(context, SensorActivity.TYPE_SENSORS[index]);
83 | } else {
84 | Toast.makeText(context, list.get(index).getName() + " OFF", Toast
85 | .LENGTH_SHORT)
86 | .show();
87 | context.unRegisterListener(context, SensorActivity.TYPE_SENSORS[index]);
88 | }
89 | break;
90 | }
91 |
92 | if (j == context.getSensors().size() - 1) {
93 | Toast.makeText(context, "The sensor isn't supported in your phone!!!",
94 | Toast.LENGTH_SHORT).show();
95 | finalHolder.sensorSwitch.setChecked(false);
96 | }
97 | }
98 | }
99 | });
100 |
101 | return view;
102 | }
103 |
104 | class ViewHolder {
105 |
106 | private TextView sensorNameView;
107 | private ImageView sensorImageView;
108 | private Switch sensorSwitch;
109 |
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/app/src/main/java/com/onlylemi/android/capture/PreviewActivity.java:
--------------------------------------------------------------------------------
1 | package com.onlylemi.android.capture;
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.support.design.widget.NavigationView;
9 | import android.support.v7.app.AppCompatActivity;
10 | import android.util.Log;
11 | import android.view.MenuItem;
12 | import android.view.View;
13 | import android.view.WindowManager;
14 | import android.widget.EditText;
15 | import android.widget.LinearLayout;
16 | import android.widget.Toast;
17 |
18 | import com.onlylemi.android.sense.SensorActivity;
19 |
20 | public class PreviewActivity extends AppCompatActivity
21 | implements NavigationView.OnNavigationItemSelectedListener, PreviewSurface.ColorListener {
22 |
23 | private final static String TAG = "PreviewActivity:";
24 |
25 | private PreviewSurface previewSurface;
26 | private ColorCrosshairView crosshairView;
27 |
28 | private String ipname = ""; // ip address
29 |
30 | private SharedPreferences sp;
31 |
32 | @Override
33 | protected void onCreate(Bundle savedInstanceState) {
34 | super.onCreate(savedInstanceState);
35 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
36 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
37 | setContentView(R.layout.activity_preview);
38 |
39 | sp = getSharedPreferences("sp", 0);
40 | ipname = sp.getString("ipname", "");
41 |
42 | // camera view
43 | previewSurface = (PreviewSurface) findViewById(R.id.preview_surface);
44 | // color id view
45 | crosshairView = (ColorCrosshairView) findViewById(R.id.crosshair);
46 | crosshairView.setVisibility(View.GONE);
47 |
48 | NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
49 | navigationView.setNavigationItemSelectedListener(this);
50 | }
51 |
52 | @Override
53 | public boolean onNavigationItemSelected(MenuItem item) {
54 | int id = item.getItemId();
55 |
56 | if (id == R.id.nav_setip) {
57 | setIdDialog();
58 | } else if (id == R.id.nav_set_colorid) {
59 | previewSurface.setColorListener(this);
60 | crosshairView.setVisibility(View.VISIBLE);
61 | } else if (id == R.id.nav_preview) {
62 | previewSurface.setColorListener(null);
63 | crosshairView.setVisibility(View.GONE);
64 | } else if (id == R.id.nav_set_sense) {
65 | Intent intent = new Intent().setClass(PreviewActivity.this, SensorActivity.class);
66 | intent.putExtra("ipname", ipname);
67 | startActivity(intent);
68 | }
69 | return true;
70 | }
71 |
72 | /**
73 | * set ip
74 | */
75 | private void setIdDialog() {
76 | final AlertDialog.Builder builder = new AlertDialog.Builder(this);
77 | builder.setTitle("Set IP To Login Server");
78 | LinearLayout loginForm = (LinearLayout) getLayoutInflater().inflate(R.layout.edit_setip,
79 | null);
80 | builder.setView(loginForm);
81 | final EditText ipnameEdit = (EditText) loginForm.findViewById(R.id.ipname);
82 | ipnameEdit.setText(ipname);
83 | builder.setPositiveButton("Login", new DialogInterface.OnClickListener() {
84 | @Override
85 | public void onClick(DialogInterface dialogInterface, int i) {
86 | ipname = ipnameEdit.getText().toString().trim();
87 | sp.edit().putString("ipname", ipname).commit();
88 |
89 | previewSurface.setIP(ipnameEdit.getText().toString().trim());
90 | Log.i(TAG, "ipname:" + ipnameEdit.getText().toString());
91 |
92 | Toast.makeText(PreviewActivity.this, "connected server : " + ipnameEdit.getText()
93 | .toString(),
94 | Toast.LENGTH_SHORT).show();
95 |
96 |
97 | }
98 | });
99 | builder.create().show();
100 | }
101 |
102 | @Override
103 | public void onColor(final int color) {
104 | crosshairView.setColor(color);
105 | }
106 |
107 | }
108 |
--------------------------------------------------------------------------------
/app/src/main/java/com/onlylemi/android/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.onlylemi.android;
2 |
3 | import android.app.AlertDialog;
4 | import android.content.DialogInterface;
5 | import android.content.Intent;
6 | import android.content.pm.PackageManager;
7 | import android.net.Uri;
8 | import android.os.Build;
9 | import android.os.Bundle;
10 | import android.provider.Settings;
11 | import android.support.annotation.NonNull;
12 | import android.support.annotation.Nullable;
13 | import android.support.v4.app.ActivityCompat;
14 | import android.support.v4.content.ContextCompat;
15 | import android.support.v7.app.AppCompatActivity;
16 |
17 | import com.onlylemi.android.capture.R;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | /**
23 | * BaseActivity
24 | *
25 | * @author qijianbin
26 | * @time 2017/3/19
27 | */
28 | public abstract class BaseActivity extends AppCompatActivity {
29 |
30 | private static final int REQUEST_CODE_PERMISSION = 202; //权限请求码
31 | private boolean isNeedCheckPermission = true; //判断是否需要检测,防止无限弹框申请权限
32 |
33 | @Override
34 | protected void onCreate(@Nullable Bundle savedInstanceState) {
35 | super.onCreate(savedInstanceState);
36 | if (isNeedCheckPermission) {
37 | checkAllNeedPermissions();
38 | }
39 | }
40 |
41 | protected void checkAllNeedPermissions() {
42 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
43 | return;
44 | }
45 | List needRequestPermissionList = getDeniedPermissions(getNeedPermissions());
46 | if (needRequestPermissionList != null && !needRequestPermissionList.isEmpty()) {
47 | ActivityCompat.requestPermissions(this, needRequestPermissionList.toArray(
48 | new String[needRequestPermissionList.size()]), REQUEST_CODE_PERMISSION);
49 | }
50 | }
51 |
52 | private List getDeniedPermissions(String[] permissions) {
53 | List needRequestPermissionList = new ArrayList<>();
54 | for (String permission : permissions) {
55 | if (ContextCompat.checkSelfPermission(this, permission) !=
56 | PackageManager.PERMISSION_GRANTED ||
57 | ActivityCompat.shouldShowRequestPermissionRationale(this, permission)) {
58 | needRequestPermissionList.add(permission);
59 | }
60 | }
61 | return needRequestPermissionList;
62 | }
63 |
64 |
65 | protected boolean isGrantedAllPermission() {
66 | List needRequestPermissionList = getDeniedPermissions(getNeedPermissions());
67 | return needRequestPermissionList.size() == 0;
68 | }
69 |
70 | @Override
71 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
72 | @NonNull int[] paramArrayOfInt) {
73 | if (requestCode == REQUEST_CODE_PERMISSION) {
74 | if (!verifyPermissions(paramArrayOfInt)) {
75 | permissionGrantedFail();
76 | showTipsDialog();
77 | isNeedCheckPermission = false;
78 | } else {
79 | permissionGrantedSuccess();
80 | }
81 | }
82 | }
83 |
84 | private boolean verifyPermissions(int[] grantResults) {
85 | for (int grantResult : grantResults) {
86 | if (grantResult != PackageManager.PERMISSION_GRANTED) {
87 | return false;
88 | }
89 | }
90 | return true;
91 | }
92 |
93 | protected void showTipsDialog() {
94 | AlertDialog.Builder builder = new AlertDialog.Builder(this);
95 | builder.setTitle("Permission")
96 | .setIcon(R.drawable.ic_warning_black_24dp)
97 | .setMessage("Current application miss " + getDialogTipsPart()
98 | + " permission, so this feature is not available. If you would go on, "
99 | + "please click the button of [OK] and go to setting center to permit!")
100 | .setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
101 | @Override
102 | public void onClick(DialogInterface dialog, int which) {
103 | finish();
104 | }
105 | })
106 | .setPositiveButton("OK", new DialogInterface.OnClickListener() {
107 | @Override
108 | public void onClick(DialogInterface dialog, int which) {
109 | startAppSettings();
110 | }
111 | })
112 | .setCancelable(false)
113 | .show();
114 | }
115 |
116 | private void startAppSettings() {
117 | Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
118 | intent.setData(Uri.parse("package:" + getPackageName()));
119 | startActivity(intent);
120 | }
121 |
122 | protected String getDialogTipsPart() {
123 | return "必要";
124 | }
125 |
126 | protected String[] getNeedPermissions() {
127 | return null;
128 | }
129 |
130 | protected void permissionGrantedSuccess() {
131 |
132 | }
133 |
134 | protected void permissionGrantedFail() {
135 |
136 | }
137 | }
138 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/java/com/onlylemi/android/sense/SensorActivity.java:
--------------------------------------------------------------------------------
1 | package com.onlylemi.android.sense;
2 |
3 | import android.content.Intent;
4 | import android.content.res.TypedArray;
5 | import android.hardware.Sensor;
6 | import android.hardware.SensorEvent;
7 | import android.hardware.SensorEventListener;
8 | import android.hardware.SensorManager;
9 | import android.support.v7.app.AppCompatActivity;
10 | import android.os.Bundle;
11 | import android.util.Log;
12 | import android.widget.ListView;
13 |
14 | import com.onlylemi.android.capture.R;
15 | import com.onlylemi.android.capture.SendDataThread;
16 |
17 | import org.json.JSONArray;
18 | import org.json.JSONException;
19 | import org.json.JSONObject;
20 |
21 | import java.io.ByteArrayInputStream;
22 | import java.io.ByteArrayOutputStream;
23 | import java.io.IOException;
24 | import java.util.ArrayList;
25 | import java.util.List;
26 |
27 | public class SensorActivity extends AppCompatActivity implements SensorEventListener {
28 |
29 | private final static String TAG = "SensorActivity";
30 |
31 | public final static int[] TYPE_SENSORS = {Sensor.TYPE_ACCELEROMETER, Sensor.TYPE_LIGHT, Sensor
32 | .TYPE_ORIENTATION, Sensor.TYPE_PROXIMITY, Sensor.TYPE_TEMPERATURE, Sensor
33 | .TYPE_PRESSURE, Sensor.TYPE_GYROSCOPE, Sensor.TYPE_MAGNETIC_FIELD};
34 | public final static String[] NAME_SENSORS = {"TYPE_ACCELEROMETER", "TYPE_LIGHT",
35 | "TYPE_ORIENTATION", "TYPE_PROXIMITY", "TYPE_TEMPERATURE"
36 | , "TYPE_PRESSURE", "TYPE_GYROSCOPE", "TYPE_MAGNETIC_FIELD"};
37 |
38 | private ListView sensorListView = null;
39 | private SensorListAdapter sensorListAdapter = null;
40 | private List sensorList;
41 |
42 | private SensorManager sensorManager = null;
43 | private List sensors;
44 |
45 | private String ipname = "";
46 |
47 |
48 | @Override
49 | protected void onCreate(Bundle savedInstanceState) {
50 | super.onCreate(savedInstanceState);
51 | setContentView(R.layout.activity_sensor);
52 |
53 | Intent intent = getIntent();
54 | ipname = intent.getStringExtra("ipname");
55 |
56 | Log.i(TAG, "ipname:" + ipname);
57 |
58 | sensorListView = (ListView) findViewById(R.id.sensor_list_view);
59 |
60 | // loading list data
61 | sensorList = loadSensorInfoDate();
62 |
63 | // set listadapter to sensorlist
64 | sensorListAdapter = new SensorListAdapter(this, sensorList);
65 | sensorListView.setAdapter(sensorListAdapter);
66 |
67 | Log.i(TAG, "sensorListAdapter init");
68 |
69 | sensorManager = (SensorManager) this.getSystemService(SENSOR_SERVICE);
70 |
71 | sensors = sensorManager.getSensorList(Sensor.TYPE_ALL);
72 | }
73 |
74 | @Override
75 | protected void onResume() {
76 | super.onResume();
77 | //registerAllSensor();
78 | }
79 |
80 | @Override
81 | protected void onPause() {
82 | super.onPause();
83 | sensorManager.unregisterListener(this);
84 | }
85 |
86 | /**
87 | * register phone all Sensor
88 | */
89 | private void registerAllSensor() {
90 | // register accelerometer sense
91 | sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor
92 | .TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_UI);
93 | // register light sense
94 | sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor
95 | .TYPE_LIGHT), SensorManager.SENSOR_DELAY_UI);
96 | // register orientation sense
97 | sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor
98 | .TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_UI);
99 | // register proximity sense
100 | sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor
101 | .TYPE_PROXIMITY), SensorManager.SENSOR_DELAY_UI);
102 | // register temperature sense
103 | sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor
104 | .TYPE_TEMPERATURE), SensorManager.SENSOR_DELAY_UI);
105 | // register pressure sense
106 | sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor
107 | .TYPE_PRESSURE), SensorManager.SENSOR_DELAY_UI);
108 | // register gyroscope sense
109 | sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor
110 | .TYPE_GYROSCOPE), SensorManager.SENSOR_DELAY_UI);
111 | // register magnetic_field sense
112 | sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor
113 | .TYPE_MAGNETIC_FIELD), SensorManager.SENSOR_DELAY_UI);
114 | }
115 |
116 | /**
117 | * load sensor data: name image
118 | *
119 | * @return sensor list
120 | */
121 | private List loadSensorInfoDate() {
122 | List sensorList = new ArrayList<>();
123 |
124 | // get sensor names
125 | String[] sensorNames = getResources().getStringArray(R.array.sensor_names);
126 | // get sensor image resources
127 | TypedArray sensorImages = getResources().obtainTypedArray(R.array.sensor_image);
128 |
129 | SensorInfo sensorInfo = null;
130 | for (int i = 0; i < sensorNames.length; i++) {
131 | sensorInfo = new SensorInfo();
132 | sensorInfo.setName(sensorNames[i]);
133 | sensorInfo.setImageId(sensorImages.getResourceId(i, 0));
134 |
135 | sensorList.add(sensorInfo);
136 | }
137 | return sensorList;
138 | }
139 |
140 | @Override
141 | public void onSensorChanged(SensorEvent sensorEvent) {
142 | JSONArray jsonArray = new JSONArray();
143 | for (int i = 0; i < TYPE_SENSORS.length; i++) {
144 | if (sensorEvent.sensor.getType() == TYPE_SENSORS[i]) {
145 | JSONObject jo = new JSONObject();
146 | try {
147 | jo.put(NAME_SENSORS[i], addJsonObject(sensorEvent));
148 | jsonArray.put(jo);
149 | } catch (JSONException e) {
150 | e.printStackTrace();
151 | }
152 | }
153 | }
154 |
155 | JSONObject json = new JSONObject();
156 | try {
157 | json.put("ANDROID_SENSOR", jsonArray);
158 | } catch (JSONException e) {
159 | e.printStackTrace();
160 | }
161 |
162 | //Log.i(TAG, "origin:" + json.toString());
163 |
164 | // encapsulation json data to i/o
165 | byte[] byteBuffer = new byte[1024];
166 | ByteArrayInputStream inputStream = new ByteArrayInputStream(json.toString().getBytes());
167 | ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
168 | try {
169 | int amount;
170 | while ((amount = inputStream.read(byteBuffer)) != -1) {
171 | outputStream.write(byteBuffer, 0, amount);
172 | }
173 | inputStream.close();
174 | outputStream.close();
175 | } catch (IOException e) {
176 | e.printStackTrace();
177 | }
178 |
179 | //Log.i(TAG, "encapsulation:" + new String(outputStream.toByteArray()));
180 |
181 | // send json data to server
182 | Thread th = new SendDataThread(outputStream, ipname, 6001);
183 | th.start();
184 | }
185 |
186 | @Override
187 | public void onAccuracyChanged(Sensor sensor, int i) {
188 |
189 | }
190 |
191 | /**
192 | * @param sensorEvent
193 | * @return
194 | */
195 | private JSONObject addJsonObject(SensorEvent sensorEvent) {
196 | JSONObject jo = new JSONObject();
197 | try {
198 | jo.put("value0", new Double(String.valueOf(sensorEvent.values[0])));
199 | jo.put("value1", new Double(String.valueOf(sensorEvent.values[1])));
200 | jo.put("value2", new Double(String.valueOf(sensorEvent.values[2])));
201 | } catch (JSONException e) {
202 | e.printStackTrace();
203 | }
204 | return jo;
205 | }
206 |
207 | /**
208 | * register sensor listener
209 | *
210 | * @param listener
211 | * @param type
212 | */
213 | public void registerListener(SensorEventListener listener, int type) {
214 | sensorManager.registerListener(listener, sensorManager.getDefaultSensor(type),
215 | SensorManager.SENSOR_DELAY_UI);
216 | }
217 |
218 | /**
219 | * unregister sensor listener
220 | *
221 | * @param listener
222 | * @param type
223 | */
224 | public void unRegisterListener(SensorEventListener listener, int type) {
225 | sensorManager.unregisterListener(listener, sensorManager.getDefaultSensor(type));
226 | }
227 |
228 | public List getSensors() {
229 | return sensors;
230 | }
231 | }
232 |
--------------------------------------------------------------------------------