Skip to content

Commit 25b8083

Browse files
authored
Merge pull request Lipotam#88 from Kimentii/development
Добавление ветки с android приложением.
2 parents c910e36 + 85d86a8 commit 25b8083

File tree

128 files changed

+3560
-1607
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+3560
-1607
lines changed
Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
*.iml
2-
.gradle
3-
/local.properties
4-
/.idea/workspace.xml
5-
/.idea/libraries
6-
.DS_Store
7-
/build
8-
/captures
9-
.externalNativeBuild
1+
*.iml
2+
/local.properties
3+
/.idea/workspace.xml
4+
/.idea/libraries
5+
.DS_Store
6+
/captures
7+
.externalNativeBuild
8+
*.log
9+
10+
# Gradle files
11+
.gradle/
12+
build/
13+
14+
# Generated files
15+
bin/
16+
gen/
17+
out/
18+

code/Java/Mobile/TestApplication/TrackPlatformAPI/app/.gitignore renamed to code/Java/Mobile/Application2.0/app/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/build
1+
/build

code/Java/Mobile/TestApplication/TrackPlatformAPI/app/build.gradle renamed to code/Java/Mobile/Application2.0/app/build.gradle

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
1-
apply plugin: 'com.android.application'
2-
3-
android {
4-
compileSdkVersion 25
5-
buildToolsVersion "25.0.2"
6-
defaultConfig {
7-
applicationId "com.example.yuras.trackplatformapi"
8-
minSdkVersion 17
9-
targetSdkVersion 25
10-
versionCode 1
11-
versionName "1.0"
12-
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
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-
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25-
exclude group: 'com.android.support', module: 'support-annotations'
26-
})
27-
compile 'com.android.support:appcompat-v7:25.1.0'
28-
compile 'com.android.support.constraint:constraint-layout:1.0.2'
29-
compile 'com.android.support:design:25.3.1'
30-
testCompile 'junit:junit:4.12'
31-
}
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 25
5+
buildToolsVersion '25.0.2'
6+
defaultConfig {
7+
applicationId "com.example.kimentii.application20"
8+
minSdkVersion 17
9+
targetSdkVersion 17
10+
versionCode 1
11+
versionName "1.0"
12+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
productFlavors {
21+
}
22+
}
23+
24+
dependencies {
25+
compile fileTree(include: ['*.jar'], dir: 'libs')
26+
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
27+
exclude group: 'com.android.support', module: 'support-annotations'
28+
})
29+
compile 'com.android.support:appcompat-v7:25.3.1'
30+
compile 'com.android.support.constraint:constraint-layout:1.0.2'
31+
testCompile 'junit:junit:4.12'
32+
}

code/Java/Mobile/TestApplication/TrackPlatformAPI/app/proguard-rules.pro renamed to code/Java/Mobile/Application2.0/app/proguard-rules.pro

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
1-
# Add project specific ProGuard rules here.
2-
# By default, the flags in this file are appended to flags specified
3-
# in C:\Users\yuras\AppData\Local\Android\Sdk/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-
#}
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in C:\Android\sdk/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+
19+
# Uncomment this to preserve the line number information for
20+
# debugging stack traces.
21+
#-keepattributes SourceFile,LineNumberTable
22+
23+
# If you keep the line number information, uncomment this to
24+
# hide the original source file name.
25+
#-renamesourcefileattribute SourceFile

code/Java/Mobile/TestApplication/TrackPlatformAPI/app/src/androidTest/java/com/example/yuras/trackplatformapi/ExampleInstrumentedTest.java renamed to code/Java/Mobile/Application2.0/app/src/androidTest/java/com/example/kimentii/application20/ExampleInstrumentedTest.java

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
package com.example.yuras.trackplatformapi;
2-
3-
import android.content.Context;
4-
import android.support.test.InstrumentationRegistry;
5-
import android.support.test.runner.AndroidJUnit4;
6-
7-
import org.junit.Test;
8-
import org.junit.runner.RunWith;
9-
10-
import static org.junit.Assert.*;
11-
12-
/**
13-
* Instrumentation test, which will execute on an Android device.
14-
*
15-
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16-
*/
17-
@RunWith(AndroidJUnit4.class)
18-
public class ExampleInstrumentedTest {
19-
@Test
20-
public void useAppContext() throws Exception {
21-
// Context of the app under test.
22-
Context appContext = InstrumentationRegistry.getTargetContext();
23-
24-
assertEquals("com.example.yuras.trackplatformapi", appContext.getPackageName());
25-
}
26-
}
1+
package com.example.kimentii.application20;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumentation test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() throws Exception {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("com.example.kimentii.application20", appContext.getPackageName());
25+
}
26+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.example.kimentii.application20">
4+
5+
<uses-permission android:name="android.permission.BLUETOOTH" />
6+
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
7+
8+
<application
9+
android:allowBackup="true"
10+
android:icon="@mipmap/ic_launcher"
11+
android:label="@string/app_name"
12+
android:roundIcon="@mipmap/ic_launcher_round"
13+
android:supportsRtl="true"
14+
android:theme="@style/AppTheme">
15+
<activity android:name=".activities.MainActivity">
16+
<intent-filter>
17+
<action android:name="android.intent.action.MAIN"/>
18+
19+
<category android:name="android.intent.category.LAUNCHER"/>
20+
</intent-filter>
21+
</activity>
22+
<activity
23+
android:name=".activities.MotionActivity"
24+
android:parentActivityName=".activities.MainActivity"/>
25+
<activity
26+
android:name=".activities.SensorsActivity"
27+
android:parentActivityName=".activities.MainActivity"/>
28+
<activity
29+
android:name=".activities.ServoActivity"
30+
android:parentActivityName=".activities.MainActivity"/>
31+
<activity
32+
android:name=".activities.SettingsActivity"
33+
android:parentActivityName=".activities.MainActivity">
34+
</activity>
35+
</application>
36+
37+
</manifest>
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
package com.example.kimentii.application20.activities;
2+
3+
import android.bluetooth.BluetoothAdapter;
4+
import android.content.Intent;
5+
import android.os.Bundle;
6+
import android.os.Handler;
7+
import android.os.Message;
8+
import android.support.v7.app.AppCompatActivity;
9+
import android.util.Log;
10+
import android.view.View;
11+
import android.widget.Button;
12+
import android.widget.TextView;
13+
14+
import com.example.kimentii.application20.R;
15+
import com.example.kimentii.application20.connectors.BluetoothConnector;
16+
import com.example.kimentii.application20.settings.Settings;
17+
import com.example.kimentii.application20.wrappers.LanguageWrapper;
18+
19+
public class MainActivity extends AppCompatActivity {
20+
21+
public static final String TAG = "TAG";
22+
private static final int REQUEST_ENABLE_BT = 1;
23+
24+
private Button motionButton;
25+
private Button servoButton;
26+
private Button sensorsButton;
27+
private Button settingsButton;
28+
private Button exitButton;
29+
private TextView connectionStateTextView;
30+
31+
private BluetoothConnector bluetoothConnector;
32+
33+
class Listener implements View.OnClickListener {
34+
Intent intent;
35+
36+
@Override
37+
public void onClick(View v) {
38+
switch (v.getId()) {
39+
case R.id.motion_button:
40+
intent = MotionActivity.newIntent(getApplicationContext());
41+
startActivity(intent);
42+
break;
43+
case R.id.servo_button:
44+
intent = ServoActivity.newIntent(getApplicationContext());
45+
startActivity(intent);
46+
break;
47+
case R.id.sensors_button:
48+
intent = SensorsActivity.newIntent(getApplicationContext());
49+
startActivity(intent);
50+
break;
51+
case R.id.settings_button:
52+
intent = SettingsActivity.newIntent(getApplicationContext());
53+
startActivity(intent);
54+
break;
55+
case R.id.exit_button:
56+
try {
57+
if (bluetoothConnector != null) {
58+
bluetoothConnector.disconnect();
59+
bluetoothConnector.join();
60+
}
61+
} catch (InterruptedException e) {
62+
e.printStackTrace();
63+
}
64+
finish();
65+
break;
66+
}
67+
}
68+
}
69+
70+
private void updateConnectionStateView() {
71+
if (bluetoothConnector != null && bluetoothConnector.isConnected()) {
72+
connectionStateTextView.setText(Settings.getInstance().getLanguageWrapper().
73+
getViewString(LanguageWrapper.CONNECTED));
74+
} else {
75+
connectionStateTextView.setText(Settings.getInstance().getLanguageWrapper().
76+
getViewString(LanguageWrapper.NO_CONNECTION));
77+
}
78+
}
79+
80+
private void setLocaleLanguage() {
81+
updateConnectionStateView();
82+
// buttons
83+
motionButton.setText(Settings.getInstance().getLanguageWrapper().
84+
getViewString(LanguageWrapper.MOTION_BUTTON));
85+
servoButton.setText(Settings.getInstance().getLanguageWrapper().
86+
getViewString(LanguageWrapper.SERVO_BUTTON));
87+
sensorsButton.setText(Settings.getInstance().getLanguageWrapper().
88+
getViewString(LanguageWrapper.SENSORS_BUTTON));
89+
settingsButton.setText(Settings.getInstance().getLanguageWrapper().
90+
getViewString(LanguageWrapper.SETTINGS_BUTTON));
91+
exitButton.setText(Settings.getInstance().getLanguageWrapper().
92+
getViewString(LanguageWrapper.EXIT_BUTTON));
93+
}
94+
95+
@Override
96+
protected void onCreate(Bundle savedInstanceState) {
97+
super.onCreate(savedInstanceState);
98+
setContentView(R.layout.activity_main);
99+
Listener listener = new Listener();
100+
motionButton = (Button) findViewById(R.id.motion_button);
101+
servoButton = (Button) findViewById(R.id.servo_button);
102+
sensorsButton = (Button) findViewById(R.id.sensors_button);
103+
settingsButton = (Button) findViewById(R.id.settings_button);
104+
exitButton = (Button) findViewById(R.id.exit_button);
105+
connectionStateTextView = (TextView) findViewById(R.id.connection_state_tv_main_activity);
106+
motionButton.setOnClickListener(listener);
107+
servoButton.setOnClickListener(listener);
108+
sensorsButton.setOnClickListener(listener);
109+
settingsButton.setOnClickListener(listener);
110+
exitButton.setOnClickListener(listener);
111+
setLocaleLanguage();
112+
113+
114+
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
115+
if (bluetoothAdapter == null) {
116+
connectionStateTextView.setText(R.string.have_no_bluetooth_module);
117+
Log.d(TAG, "You have no bluetooth.");
118+
}
119+
if (bluetoothAdapter != null && bluetoothAdapter.isEnabled()) {
120+
Handler handler = new Handler() {
121+
@Override
122+
public void handleMessage(Message msg) {
123+
super.handleMessage(msg);
124+
125+
}
126+
};
127+
bluetoothConnector = BluetoothConnector.getInstance();
128+
bluetoothConnector.connect();
129+
bluetoothConnector.setHandler(handler);
130+
updateConnectionStateView();
131+
} else {
132+
// Bluetooth выключен. Предложим пользователю включить его.
133+
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
134+
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
135+
}
136+
137+
}
138+
139+
@Override
140+
protected void onResume() {
141+
super.onResume();
142+
setLocaleLanguage();
143+
}
144+
145+
@Override
146+
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
147+
super.onActivityResult(requestCode, resultCode, data);
148+
if (requestCode == REQUEST_ENABLE_BT && requestCode == RESULT_OK) {
149+
Log.d(TAG, "Bluetooth connected");
150+
Handler handler = new Handler() {
151+
@Override
152+
public void handleMessage(Message msg) {
153+
super.handleMessage(msg);
154+
155+
}
156+
};
157+
bluetoothConnector = BluetoothConnector.getInstance();
158+
bluetoothConnector.connect();
159+
bluetoothConnector.setHandler(handler);
160+
updateConnectionStateView();
161+
}
162+
}
163+
164+
}

0 commit comments

Comments
 (0)