Skip to content

Commit 77afb6d

Browse files
committed
✨ upload BlueToothDemo
1 parent c0efb0b commit 77afb6d

36 files changed

+1136
-0
lines changed

BlueToothDemo/.gitignore

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
2+
# Created by https://www.gitignore.io/api/java,kotlin,android,androidstudio
3+
4+
### Android ###
5+
# Built application files
6+
*.apk
7+
*.ap_
8+
9+
# Files for the ART/Dalvik VM
10+
*.dex
11+
12+
# Java class files
13+
*.class
14+
15+
# Generated files
16+
bin/
17+
gen/
18+
out/
19+
20+
# Gradle files
21+
.gradle/
22+
build/
23+
24+
# Local configuration file (sdk path, etc)
25+
local.properties
26+
27+
# Proguard folder generated by Eclipse
28+
proguard/
29+
30+
# Log Files
31+
*.log
32+
33+
# Android Studio Navigation editor temp files
34+
.navigation/
35+
36+
# Android Studio captures folder
37+
captures/
38+
39+
# Intellij
40+
*.iml
41+
.idea/workspace.xml
42+
.idea/tasks.xml
43+
.idea/gradle.xml
44+
.idea/dictionaries
45+
.idea/libraries
46+
47+
# External native build folder generated in Android Studio 2.2 and later
48+
.externalNativeBuild
49+
50+
# Freeline
51+
freeline.py
52+
freeline/
53+
freeline_project_description.json
54+
55+
### Android Patch ###
56+
gen-external-apklibs
57+
58+
### AndroidStudio ###
59+
# Covers files to be ignored for android development using Android Studio.
60+
61+
# Built application files
62+
63+
# Files for the ART/Dalvik VM
64+
65+
# Java class files
66+
67+
# Generated files
68+
69+
# Gradle files
70+
.gradle
71+
72+
# Signing files
73+
.signing/
74+
75+
# Local configuration file (sdk path, etc)
76+
77+
# Proguard folder generated by Eclipse
78+
79+
# Log Files
80+
81+
# Android Studio
82+
/*/build/
83+
/*/local.properties
84+
/*/out
85+
/*/*/build
86+
/*/*/production
87+
*.ipr
88+
*~
89+
*.swp
90+
91+
# Android Patch
92+
93+
# External native build folder generated in Android Studio 2.2 and later
94+
95+
# NDK
96+
obj/
97+
98+
# IntelliJ IDEA
99+
*.iws
100+
/out/
101+
102+
# User-specific configurations
103+
.idea/libraries/
104+
.idea/.name
105+
.idea/compiler.xml
106+
.idea/copyright/profiles_settings.xml
107+
.idea/encodings.xml
108+
.idea/misc.xml
109+
.idea/modules.xml
110+
.idea/scopes/scope_settings.xml
111+
.idea/vcs.xml
112+
.idea/jsLibraryMappings.xml
113+
.idea/datasources.xml
114+
.idea/dataSources.ids
115+
.idea/sqlDataSources.xml
116+
.idea/dynamic.xml
117+
.idea/uiDesigner.xml
118+
119+
# OS-specific files
120+
.DS_Store
121+
.DS_Store?
122+
._*
123+
.Spotlight-V100
124+
.Trashes
125+
ehthumbs.db
126+
Thumbs.db
127+
128+
# Legacy Eclipse project files
129+
.classpath
130+
.project
131+
.cproject
132+
.settings/
133+
134+
# Mobile Tools for Java (J2ME)
135+
.mtj.tmp/
136+
137+
# Package Files #
138+
*.war
139+
*.ear
140+
141+
# virtual machine crash logs (Reference: http://www.java.com/en/download/help/error_hotspot.xml)
142+
hs_err_pid*
143+
144+
## Plugin-specific files:
145+
146+
# mpeltonen/sbt-idea plugin
147+
.idea_modules/
148+
149+
# JIRA plugin
150+
atlassian-ide-plugin.xml
151+
152+
# Mongo Explorer plugin
153+
.idea/mongoSettings.xml
154+
155+
# Crashlytics plugin (for Android Studio and IntelliJ)
156+
com_crashlytics_export_strings.xml
157+
crashlytics.properties
158+
crashlytics-build.properties
159+
fabric.properties
160+
161+
### AndroidStudio Patch ###
162+
163+
!/gradle/wrapper/gradle-wrapper.jar
164+
165+
### Java ###
166+
# Compiled class file
167+
168+
# Log file
169+
170+
# BlueJ files
171+
*.ctxt
172+
173+
# Mobile Tools for Java (J2ME)
174+
175+
# Package Files #
176+
*.jar
177+
*.zip
178+
*.tar.gz
179+
*.rar
180+
181+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
182+
183+
### Kotlin ###
184+
# Compiled class file
185+
186+
# Log file
187+
188+
# BlueJ files
189+
190+
# Mobile Tools for Java (J2ME)
191+
192+
# Package Files #
193+
194+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
195+
196+
197+
# End of https://www.gitignore.io/api/java,kotlin,android,androidstudio

BlueToothDemo/app/.gitignore

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

BlueToothDemo/app/build.gradle

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
apply plugin: 'com.android.application'
2+
3+
apply plugin: 'kotlin-android'
4+
5+
apply plugin: 'kotlin-android-extensions'
6+
7+
android {
8+
compileSdkVersion 26
9+
defaultConfig {
10+
applicationId "io.innofang.bluetoothdemo"
11+
minSdkVersion 21
12+
targetSdkVersion 26
13+
versionCode 1
14+
versionName "1.0"
15+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16+
}
17+
buildTypes {
18+
release {
19+
minifyEnabled false
20+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21+
}
22+
}
23+
}
24+
25+
dependencies {
26+
implementation fileTree(dir: 'libs', include: ['*.jar'])
27+
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
28+
implementation 'com.android.support:appcompat-v7:26.1.0'
29+
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
30+
testImplementation 'junit:junit:4.12'
31+
androidTestImplementation 'com.android.support.test:runner:1.0.1'
32+
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
33+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package io.innofang.bluetoothdemo
2+
3+
import android.support.test.InstrumentationRegistry
4+
import android.support.test.runner.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class ExampleInstrumentedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getTargetContext()
22+
assertEquals("io.innofang.bluetoothdemo", appContext.packageName)
23+
}
24+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="io.innofang.bluetoothdemo">
4+
5+
<uses-permission android:name="android.permission.BLUETOOTH"/>
6+
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
7+
<uses-permission-sdk-23 android:name="android.permission.ACCESS_COARSE_LOCATION"/>
8+
9+
<application
10+
android:allowBackup="true"
11+
android:icon="@mipmap/ic_launcher"
12+
android:label="@string/app_name"
13+
android:roundIcon="@mipmap/ic_launcher_round"
14+
android:supportsRtl="true"
15+
android:theme="@style/AppTheme">
16+
<activity android:name=".MainActivity">
17+
<intent-filter>
18+
<action android:name="android.intent.action.MAIN"/>
19+
20+
<category android:name="android.intent.category.LAUNCHER"/>
21+
</intent-filter>
22+
</activity>
23+
</application>
24+
25+
</manifest>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package io.innofang.bluetoothdemo
2+
3+
import android.app.Activity
4+
import android.bluetooth.BluetoothAdapter
5+
import android.content.Intent
6+
7+
/**
8+
* Author: Inno Fang
9+
* Time: 2018/3/16 16:35
10+
* Description:
11+
*/
12+
13+
class BlueToothController {
14+
private val adapter = BluetoothAdapter.getDefaultAdapter()
15+
16+
fun isSupportBlueTooth() = adapter != null
17+
18+
fun getBlueToothStatus(): Boolean {
19+
assert(adapter != null)
20+
return adapter.isEnabled
21+
}
22+
23+
fun turnOnBlueTooth(activity: Activity, requestCode: Int){
24+
val intent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
25+
activity.startActivityForResult(intent, requestCode)
26+
}
27+
28+
fun turnOffBlueTooth() = adapter.disable()
29+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.innofang.bluetoothdemo
2+
3+
import android.util.Log
4+
5+
/**
6+
* Author: Inno Fang
7+
* Time: 2018/3/16 17:09
8+
* Description:
9+
*/
10+
11+
val TAG = "BlueToothDemo"
12+
13+
fun Any.i() = Log.i(TAG, "$this")
14+
fun Any.d() = Log.i(TAG, "$this")
15+
fun Any.e() = Log.i(TAG, "$this")
16+
fun Any.w() = Log.i(TAG, "$this")
17+
fun Any.v() = Log.i(TAG, "$this")

0 commit comments

Comments
 (0)