Skip to content

Commit 03f983a

Browse files
Initial commit
1 parent 3392e86 commit 03f983a

File tree

24 files changed

+458
-0
lines changed

24 files changed

+458
-0
lines changed

AndroidSensor/.classpath

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="src" path="gen"/>
5+
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
6+
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
7+
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
8+
<classpathentry kind="output" path="bin/classes"/>
9+
</classpath>

AndroidSensor/.gitignore

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Built application files
2+
*.apk
3+
*.ap_
4+
5+
# Files for the Dalvik VM
6+
*.dex
7+
8+
# Java class files
9+
*.class
10+
11+
# Generated files
12+
bin/
13+
gen/
14+
15+
# Gradle files
16+
.gradle/
17+
build/
18+
19+
# Local configuration file (sdk path, etc)
20+
local.properties
21+
22+
# Proguard folder generated by Eclipse
23+
proguard/
24+
25+
#Idea Dir
26+
.idea/
27+
28+
*.iml

AndroidSensor/.project

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>AndroidSensor</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.jdt.core.javabuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
<buildCommand>
24+
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
25+
<arguments>
26+
</arguments>
27+
</buildCommand>
28+
</buildSpec>
29+
<natures>
30+
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
31+
<nature>org.eclipse.jdt.core.javanature</nature>
32+
</natures>
33+
</projectDescription>

AndroidSensor/AndroidManifest.xml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ *******************************************************************************
4+
~ Copyright (c) 2013-2014 Francesco Azzola (http://www.survivingwithandroid.com).
5+
~
6+
~ Licensed under the Apache License, Version 2.0 (the "License");
7+
~ you may not use this file except in compliance with the License.
8+
~ You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
~ *****************************************************************************
18+
-->
19+
20+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
21+
package="com.survivingwithandroid.sensor"
22+
android:versionCode="1"
23+
android:versionName="1.0" >
24+
25+
<uses-sdk
26+
android:minSdkVersion="8"
27+
android:targetSdkVersion="17" />
28+
29+
30+
<application
31+
android:allowBackup="true"
32+
android:icon="@drawable/ic_launcher"
33+
android:label="@string/app_name"
34+
android:theme="@style/AppTheme" >
35+
<activity
36+
android:name="com.survivingwithandroid.sensor.MainActivity"
37+
android:label="@string/app_name" >
38+
<intent-filter>
39+
<action android:name="android.intent.action.MAIN" />
40+
41+
<category android:name="android.intent.category.LAUNCHER" />
42+
</intent-filter>
43+
</activity>
44+
<activity
45+
android:name="com.survivingwithandroid.sensor.PressActivity" />
46+
</application>
47+
48+
</manifest>

AndroidSensor/ic_launcher-web.png

50.2 KB
Loading
543 KB
Binary file not shown.

AndroidSensor/proguard-project.txt

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# To enable ProGuard in your project, edit project.properties
2+
# to define the proguard.config property as described in that file.
3+
#
4+
# Add project specific ProGuard rules here.
5+
# By default, the flags in this file are appended to flags specified
6+
# in ${sdk.dir}/tools/proguard/proguard-android.txt
7+
# You can edit the include path and order by changing the ProGuard
8+
# include property in project.properties.
9+
#
10+
# For more details, see
11+
# http://developer.android.com/guide/developing/tools/proguard.html
12+
13+
# Add any project specific keep options here:
14+
15+
# If your project uses WebView with JS, uncomment the following
16+
# and specify the fully qualified class name to the JavaScript interface
17+
# class:
18+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19+
# public *;
20+
#}

AndroidSensor/project.properties

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This file is automatically generated by Android Tools.
2+
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3+
#
4+
# This file must be checked in Version Control Systems.
5+
#
6+
# To customize properties used by the Ant build system edit
7+
# "ant.properties", and override values to adapt the script to your
8+
# project structure.
9+
#
10+
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11+
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12+
13+
# Project target.
14+
target=android-17
7.48 KB
Loading
3.69 KB
Loading
12.2 KB
Loading
Loading
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:paddingBottom="@dimen/activity_vertical_margin"
6+
android:paddingLeft="@dimen/activity_horizontal_margin"
7+
android:paddingRight="@dimen/activity_horizontal_margin"
8+
android:paddingTop="@dimen/activity_vertical_margin"
9+
tools:context=".MainActivity" >
10+
11+
<ListView android:id="@+id/sensorList"
12+
android:layout_width="match_parent"
13+
android:layout_height="match_parent"
14+
15+
/>
16+
17+
</RelativeLayout>
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent" >
5+
6+
<TextView android:id="@+id/text" android:text="Pressure (mbar)"
7+
style="?android:attr/textAppearanceLarge"
8+
android:layout_width="wrap_content"
9+
android:layout_height="wrap_content"
10+
android:layout_centerHorizontal="true"/>
11+
12+
<LinearLayout android:id="@+id/l1"
13+
android:layout_width="160dp"
14+
android:layout_height="80dp"
15+
android:layout_centerInParent="true"
16+
android:background="#d3e4f4"
17+
>
18+
19+
<TextView
20+
android:id="@+id/pressTxt"
21+
android:layout_width="wrap_content"
22+
android:layout_height="wrap_content"
23+
android:gravity="center_horizontal"
24+
style="@style/pressStyle" />
25+
26+
</LinearLayout>
27+
28+
</RelativeLayout>

AndroidSensor/res/menu/main.xml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
2+
3+
<item
4+
android:id="@+id/press"
5+
android:orderInCategory="100"
6+
android:showAsAction="never"
7+
android:title="Pressure sensor"/>
8+
9+
</menu>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<resources>
2+
3+
<!--
4+
Customize dimensions originally defined in res/values/dimens.xml (such as
5+
screen margins) for sw600dp devices (e.g. 7" tablets) here.
6+
-->
7+
8+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<resources>
2+
3+
<!--
4+
Customize dimensions originally defined in res/values/dimens.xml (such as
5+
screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.
6+
-->
7+
<dimen name="activity_horizontal_margin">128dp</dimen>
8+
9+
</resources>
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<resources>
2+
3+
<!--
4+
Base application theme for API 11+. This theme completely replaces
5+
AppBaseTheme from res/values/styles.xml on API 11+ devices.
6+
-->
7+
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
8+
<!-- API 11 theme customizations can go here. -->
9+
</style>
10+
11+
</resources>
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<resources>
2+
3+
<!--
4+
Base application theme for API 14+. This theme completely replaces
5+
AppBaseTheme from BOTH res/values/styles.xml and
6+
res/values-v11/styles.xml on API 14+ devices.
7+
-->
8+
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
9+
<!-- API 14 theme customizations can go here. -->
10+
</style>
11+
12+
</resources>

AndroidSensor/res/values/dimens.xml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<resources>
2+
3+
<!-- Default screen margins, per the Android Design guidelines. -->
4+
<dimen name="activity_horizontal_margin">16dp</dimen>
5+
<dimen name="activity_vertical_margin">16dp</dimen>
6+
7+
</resources>

AndroidSensor/res/values/strings.xml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
4+
<string name="app_name">AndroidSensor</string>
5+
<string name="action_settings">Settings</string>
6+
<string name="hello_world">Hello world!</string>
7+
8+
</resources>

AndroidSensor/res/values/styles.xml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<resources>
2+
3+
<!--
4+
Base application theme, dependent on API level. This theme is replaced
5+
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
6+
-->
7+
<style name="AppBaseTheme" parent="android:Theme.Light">
8+
<!--
9+
Theme customizations available in newer API levels can go in
10+
res/values-vXX/styles.xml, while customizations related to
11+
backward-compatibility can go here.
12+
-->
13+
</style>
14+
15+
<!-- Application theme. -->
16+
<style name="AppTheme" parent="AppBaseTheme">
17+
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
18+
</style>
19+
20+
<style name="pressStyle" parent="@android:style/TextAppearance.Large">
21+
<item name="android:textColor">#2E9AFE</item>
22+
<item name="android:textStyle">normal</item>
23+
<item name="android:textSize">60dp</item>
24+
</style>
25+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package com.survivingwithandroid.sensor;
2+
3+
import java.util.ArrayList;
4+
import java.util.HashMap;
5+
import java.util.List;
6+
import java.util.Map;
7+
8+
import android.hardware.Sensor;
9+
import android.hardware.SensorEventListener;
10+
import android.hardware.SensorManager;
11+
import android.os.Bundle;
12+
import android.app.Activity;
13+
import android.app.Service;
14+
import android.content.Intent;
15+
import android.view.Menu;
16+
import android.view.View;
17+
import android.widget.AdapterView;
18+
import android.widget.ListView;
19+
import android.widget.SimpleAdapter;
20+
21+
/*
22+
* Copyright (C) 2014 Francesco Azzola - Surviving with Android (http://www.survivingwithandroid.com)
23+
*
24+
* Licensed under the Apache License, Version 2.0 (the "License");
25+
* you may not use this file except in compliance with the License.
26+
* You may obtain a copy of the License at
27+
*
28+
* http://www.apache.org/licenses/LICENSE-2.0
29+
*
30+
* Unless required by applicable law or agreed to in writing, software
31+
* distributed under the License is distributed on an "AS IS" BASIS,
32+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33+
* See the License for the specific language governing permissions and
34+
* limitations under the License.
35+
*/
36+
public class MainActivity extends Activity {
37+
private SensorManager sensorManager;
38+
39+
@Override
40+
protected void onCreate(Bundle savedInstanceState) {
41+
super.onCreate(savedInstanceState);
42+
setContentView(R.layout.activity_main);
43+
44+
// Get the reference to the sensor manager
45+
sensorManager = (SensorManager) getSystemService(Service.SENSOR_SERVICE);
46+
47+
// Get the list of sensor
48+
//List<Sensor> sensorList = sensorManager.getSensorList(Sensor.TYPE_ALL);
49+
50+
List<Sensor> sensorList = sensorManager.getSensorList(Sensor.TYPE_PRESSURE);
51+
52+
List<Map<String, String>> sensorData = new ArrayList<Map<String,String>>();
53+
54+
55+
for (Sensor sensor: sensorList) {
56+
Map<String, String> data = new HashMap<String, String>();
57+
data.put("name", sensor.getName());
58+
data.put("vendor", sensor.getVendor());
59+
sensorData.add(data);
60+
}
61+
62+
63+
SimpleAdapter sa = new SimpleAdapter(this, sensorData, android.R.layout.simple_list_item_2, new String[]{"name", "vendor"}, new int[]{android.R.id.text1, android.R.id.text2});
64+
65+
ListView lv = (ListView) findViewById(R.id.sensorList);
66+
lv.setAdapter(sa);
67+
68+
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
69+
70+
@Override
71+
public void onItemClick(AdapterView<?> parent, View view, int pos,
72+
long id) {
73+
74+
Intent i = new Intent(MainActivity.this, PressActivity.class);
75+
startActivity(i);
76+
77+
}
78+
});
79+
80+
}
81+
82+
@Override
83+
public boolean onCreateOptionsMenu(Menu menu) {
84+
// Inflate the menu; this adds items to the action bar if it is present.
85+
getMenuInflater().inflate(R.menu.main, menu);
86+
return true;
87+
}
88+
89+
}

0 commit comments

Comments
 (0)