├── .gitattributes ├── .gitignore ├── README.md └── android-multiple-bluetooth-connections └── ViewTutorialPart2-master ├── .gitignore ├── .settings └── org.eclipse.jdt.core.prefs ├── AndroidManifest.xml ├── proguard.cfg ├── project.properties ├── res ├── drawable-hdpi │ ├── ic_action_new.png │ ├── ic_drawer.png │ ├── ic_list_remove.png │ └── jayway_logo.png ├── drawable-ldpi │ └── jayway_logo.png ├── drawable-mdpi │ └── jayway_logo.png ├── layout │ ├── activity_layout_changes.xml │ ├── activity_layout_changes_sub.xml │ ├── list_item_example.xml │ ├── main.xml │ └── view_sub.xml └── values │ ├── colors.xml │ ├── ids.xml │ └── strings.xml └── src └── com └── jayway └── viewtutorial └── part2 ├── DirectionView.java ├── LayoutChangesActivity.java ├── LineChartView.java ├── MyService0.java ├── MyService1.java ├── MyService2.java └── ViewTutorialActivity.java /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # ========================= 18 | # Operating System Files 19 | # ========================= 20 | 21 | # OSX 22 | # ========================= 23 | 24 | .DS_Store 25 | .AppleDouble 26 | .LSOverride 27 | 28 | # Icon must ends with two \r. 29 | Icon 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear on external disk 35 | .Spotlight-V100 36 | .Trashes 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | android-multiple-bluetooth-connections 2 | ====================================== 3 | Android phone CAN communicate with multiply bluetooth devices at same time using Bluetooth Low Engery or Bluetooth Classic.
4 | **Bluetooth Classic**
5 | This code is designed to communicate with three bluetooth Classic devices using three services. MyService1.java and MyService2.java are related to the three bluetooth devices. The MAC address in the three files should be modified accordingly. MyService0.java is a dummy service, which make the demo working. The origrinal code is designed to show the reading from multiple airflow sensors. In my experiment, the three Bluetooth Classic connections can work but not stable. As Bluetooth Classic evolves, this code may not be the best solution. However, it is a good demo
6 | 7 | **Bluetooth Low Engery**
8 | Please refer to BluetoothLeGatt from Offical Android. After reading the tutorial, the multiple BLE connections can be achieved by storing all the BLE connections.
9 | I achieved the multiply BLE connections using Andorid phone and Bluefruit LE Micro Arduino Boards (Adafruit website). 10 | -------------------------------------------------------------------------------- /android-multiple-bluetooth-connections/ViewTutorialPart2-master/.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # files for the dex VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # generated files 12 | bin/ 13 | gen/ 14 | 15 | # Local configuration file (sdk path, etc) 16 | local.properties 17 | 18 | # Eclipse project files 19 | .classpath 20 | .project 21 | -------------------------------------------------------------------------------- /android-multiple-bluetooth-connections/ViewTutorialPart2-master/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 3 | org.eclipse.jdt.core.compiler.compliance=1.6 4 | org.eclipse.jdt.core.compiler.source=1.6 5 | -------------------------------------------------------------------------------- /android-multiple-bluetooth-connections/ViewTutorialPart2-master/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 12 | 15 | 16 | 17 | 18 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /android-multiple-bluetooth-connections/ViewTutorialPart2-master/proguard.cfg: -------------------------------------------------------------------------------- 1 | -optimizationpasses 5 2 | -dontusemixedcaseclassnames 3 | -dontskipnonpubliclibraryclasses 4 | -dontpreverify 5 | -verbose 6 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* 7 | 8 | -keep public class * extends android.app.Activity 9 | -keep public class * extends android.app.Application 10 | -keep public class * extends android.app.Service 11 | -keep public class * extends android.content.BroadcastReceiver 12 | -keep public class * extends android.content.ContentProvider 13 | -keep public class * extends android.app.backup.BackupAgentHelper 14 | -keep public class * extends android.preference.Preference 15 | -keep public class com.android.vending.licensing.ILicensingService 16 | 17 | -keepclasseswithmembernames class * { 18 | native ; 19 | } 20 | 21 | -keepclasseswithmembers class * { 22 | public (android.content.Context, android.util.AttributeSet); 23 | } 24 | 25 | -keepclasseswithmembers class * { 26 | public (android.content.Context, android.util.AttributeSet, int); 27 | } 28 | 29 | -keepclassmembers class * extends android.app.Activity { 30 | public void *(android.view.View); 31 | } 32 | 33 | -keepclassmembers enum * { 34 | public static **[] values(); 35 | public static ** valueOf(java.lang.String); 36 | } 37 | 38 | -keep class * implements android.os.Parcelable { 39 | public static final android.os.Parcelable$Creator *; 40 | } 41 | -------------------------------------------------------------------------------- /android-multiple-bluetooth-connections/ViewTutorialPart2-master/project.properties: -------------------------------------------------------------------------------- 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 use, 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | 10 | # Project target. 11 | target=android-19 12 | -------------------------------------------------------------------------------- /android-multiple-bluetooth-connections/ViewTutorialPart2-master/res/drawable-hdpi/ic_action_new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alanxuefei/android-multiple-bluetooth-connections/76739585c5a4ca374f248f8648dcab4c28ad10ae/android-multiple-bluetooth-connections/ViewTutorialPart2-master/res/drawable-hdpi/ic_action_new.png -------------------------------------------------------------------------------- /android-multiple-bluetooth-connections/ViewTutorialPart2-master/res/drawable-hdpi/ic_drawer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alanxuefei/android-multiple-bluetooth-connections/76739585c5a4ca374f248f8648dcab4c28ad10ae/android-multiple-bluetooth-connections/ViewTutorialPart2-master/res/drawable-hdpi/ic_drawer.png -------------------------------------------------------------------------------- /android-multiple-bluetooth-connections/ViewTutorialPart2-master/res/drawable-hdpi/ic_list_remove.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alanxuefei/android-multiple-bluetooth-connections/76739585c5a4ca374f248f8648dcab4c28ad10ae/android-multiple-bluetooth-connections/ViewTutorialPart2-master/res/drawable-hdpi/ic_list_remove.png -------------------------------------------------------------------------------- /android-multiple-bluetooth-connections/ViewTutorialPart2-master/res/drawable-hdpi/jayway_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alanxuefei/android-multiple-bluetooth-connections/76739585c5a4ca374f248f8648dcab4c28ad10ae/android-multiple-bluetooth-connections/ViewTutorialPart2-master/res/drawable-hdpi/jayway_logo.png -------------------------------------------------------------------------------- /android-multiple-bluetooth-connections/ViewTutorialPart2-master/res/drawable-ldpi/jayway_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alanxuefei/android-multiple-bluetooth-connections/76739585c5a4ca374f248f8648dcab4c28ad10ae/android-multiple-bluetooth-connections/ViewTutorialPart2-master/res/drawable-ldpi/jayway_logo.png -------------------------------------------------------------------------------- /android-multiple-bluetooth-connections/ViewTutorialPart2-master/res/drawable-mdpi/jayway_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alanxuefei/android-multiple-bluetooth-connections/76739585c5a4ca374f248f8648dcab4c28ad10ae/android-multiple-bluetooth-connections/ViewTutorialPart2-master/res/drawable-mdpi/jayway_logo.png -------------------------------------------------------------------------------- /android-multiple-bluetooth-connections/ViewTutorialPart2-master/res/layout/activity_layout_changes.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 21 | 22 | 24 | 26 | 27 | 30 | 41 | 42 | 43 | 44 | 45 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /android-multiple-bluetooth-connections/ViewTutorialPart2-master/res/layout/activity_layout_changes_sub.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /android-multiple-bluetooth-connections/ViewTutorialPart2-master/res/layout/list_item_example.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 26 | 27 | 28 | 37 | 38 | 47 | 48 | 57 | 58 | 59 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /android-multiple-bluetooth-connections/ViewTutorialPart2-master/res/layout/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 15 | 16 | 17 | 18 | 25 | 26 | -------------------------------------------------------------------------------- /android-multiple-bluetooth-connections/ViewTutorialPart2-master/res/layout/view_sub.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /android-multiple-bluetooth-connections/ViewTutorialPart2-master/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #33B5E5 4 | #FFFFFF 5 | #FFFFFF 6 | -------------------------------------------------------------------------------- /android-multiple-bluetooth-connections/ViewTutorialPart2-master/res/values/ids.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /android-multiple-bluetooth-connections/ViewTutorialPart2-master/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | AirflowSensor 5 | Settings 6 | Hello world! 7 | N 8 | E 9 | S 10 | W 11 | 12 | Add an airflow sensor above to get started. 13 | Touch a photo to expand it. 14 | 15 | Toggle indicator 16 | Add item 17 | Remove item 18 | Previous 19 | Next 20 | Finish 21 | Photo info 22 | View photo 23 | 24 | -------------------------------------------------------------------------------- /android-multiple-bluetooth-connections/ViewTutorialPart2-master/src/com/jayway/viewtutorial/part2/DirectionView.java: -------------------------------------------------------------------------------- 1 | package com.jayway.viewtutorial.part2; 2 | 3 | import android.content.Context; 4 | import android.content.res.Resources; 5 | import android.graphics.*; 6 | import android.view.*; 7 | import android.util.AttributeSet; 8 | import android.util.Log; 9 | 10 | public class DirectionView extends View { 11 | 12 | // Paints used to draw the Compass 13 | private Paint markerPaint; 14 | private Paint textPaint; 15 | private Paint circlePaint; 16 | private Paint ReadingPaint; 17 | 18 | // Cardinal point Strings 19 | private String northString; 20 | private String eastString; 21 | private String southString; 22 | private String westString; 23 | 24 | // Height of text 25 | private int textHeight; 26 | private float bearing; 27 | private float airflowSpeed; 28 | 29 | 30 | /** Get or set the bearing displayed by the compass **/ 31 | public void setBearing(float _bearing,float _speed) { 32 | this.bearing = _bearing; 33 | this.airflowSpeed=_speed; 34 | invalidate(); 35 | 36 | } 37 | public float getBearing() { 38 | return bearing; 39 | } 40 | 41 | 42 | /** Constructors **/ 43 | public DirectionView(Context context) { 44 | super(context); 45 | initCompassView(); 46 | } 47 | 48 | public DirectionView(Context context, AttributeSet attrs) { 49 | super(context, attrs); 50 | initCompassView(); 51 | } 52 | 53 | public DirectionView(Context context, AttributeSet attrs, int defaultStyle) { 54 | super(context, attrs, defaultStyle); 55 | initCompassView(); 56 | } 57 | 58 | /** Initialize the Class variables **/ 59 | protected void initCompassView() { 60 | setFocusable(true); 61 | 62 | // Get a reference to the external resources 63 | Resources r = this.getResources(); 64 | northString = r.getString(R.string.cardinal_north); 65 | eastString = r.getString(R.string.cardinal_east); 66 | southString = r.getString(R.string.cardinal_south); 67 | westString = r.getString(R.string.cardinal_west); 68 | 69 | // Create the paints 70 | circlePaint = new Paint(Paint.ANTI_ALIAS_FLAG); 71 | circlePaint.setColor(r.getColor(R.color.background_color)); 72 | circlePaint.setStrokeWidth(4); 73 | circlePaint.setStyle(Paint.Style.FILL_AND_STROKE); 74 | 75 | markerPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 76 | markerPaint.setColor(r.getColor(R.color.marker_color)); 77 | markerPaint.setStrokeWidth(10); 78 | 79 | textPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 80 | textPaint.setColor(r.getColor(R.color.text_color)); 81 | textPaint.setStrokeWidth(10); 82 | 83 | ReadingPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 84 | ReadingPaint.setColor(r.getColor(R.color.text_color)); 85 | ReadingPaint.setStrokeWidth(10); 86 | ReadingPaint.setTextSize(28); 87 | 88 | textHeight = (int)textPaint.measureText("yY"); 89 | } 90 | 91 | @Override 92 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 93 | // The compass is a circle that fills as much space as possible. 94 | // Set the measured dimensions by figuring out the shortest boundary, 95 | // height or width. 96 | int measuredWidth = measure(widthMeasureSpec); 97 | int measuredHeight = measure(heightMeasureSpec); 98 | 99 | int d = Math.min(measuredWidth, measuredHeight+30); 100 | 101 | setMeasuredDimension(measuredWidth, d); 102 | } 103 | 104 | private int measure(int measureSpec) { 105 | int result = 0; 106 | 107 | // Decode the measurement specifications. 108 | int specMode = MeasureSpec.getMode(measureSpec); 109 | int specSize = MeasureSpec.getSize(measureSpec); 110 | 111 | if (specMode == MeasureSpec.UNSPECIFIED) { 112 | // Return a default size of 200 if no bounds are specified. 113 | result = 200; 114 | } else { 115 | // As you want to fill the available space 116 | // always return the full available bounds. 117 | result = specSize; 118 | } 119 | return result; 120 | } 121 | 122 | @Override 123 | protected void onDraw(Canvas canvas) { 124 | int px = getMeasuredWidth() / 2; 125 | int py = getMeasuredHeight() / 2; 126 | 127 | int radius = Math.min(px, py)-30; 128 | 129 | // Draw the background 130 | canvas.drawCircle(px, py, radius, circlePaint); 131 | 132 | // Rotate our perspective so that the 'top' is facing the current bearing. 133 | canvas.save(); 134 | // canvas.rotate(-bearing, px, py); 135 | int textWidth = (int)textPaint.measureText("W"); 136 | int cardinalX = px-textWidth/2; 137 | int cardinalY = py-radius+textHeight; 138 | 139 | // Draw the marker every 15 degrees and a text every 45. 140 | for (int i = 0; i < 24; i++) { 141 | // Draw a marker. 142 | canvas.drawLine(px, py-radius, px, py-radius+10, markerPaint); 143 | 144 | canvas.save(); 145 | canvas.translate(0, textHeight); 146 | 147 | // Draw the cardinal points 148 | if (i % 6 == 0) { 149 | String dirString = ""; 150 | switch (i) { 151 | case(0) : { 152 | dirString = northString; 153 | // int arrowY = 2*textHeight; 154 | //canvas.drawLine(px, arrowY, px-5, 3*textHeight, markerPaint); 155 | //canvas.drawLine(px, arrowY, px+5, 3*textHeight, markerPaint); 156 | break; 157 | } 158 | case(6) : dirString = eastString; break; 159 | case(12) : dirString = southString; break; 160 | case(18) : dirString = westString; break; 161 | } 162 | 163 | canvas.drawText(dirString, cardinalX, cardinalY, textPaint); 164 | } 165 | 166 | else if (i % 3 == 0) { 167 | // Draw the text every alternate 45deg 168 | String angle = String.valueOf(i*15); 169 | float angleTextWidth = textPaint.measureText(angle); 170 | 171 | int angleTextX = (int)(px-angleTextWidth/2); 172 | int angleTextY = py-radius+textHeight; 173 | canvas.drawText(angle, angleTextX, angleTextY, textPaint); 174 | } 175 | canvas.restore(); 176 | canvas.rotate(15, px, py); 177 | } 178 | 179 | canvas.rotate(-bearing, px, py); 180 | int arrowY = 6*textHeight; 181 | canvas.drawLine(px, arrowY, px-5, 3*textHeight, markerPaint); 182 | canvas.drawLine(px, arrowY, px+5, 3*textHeight, markerPaint); 183 | 184 | canvas.restore(); 185 | ReadingPaint.setTextSize(75); 186 | canvas.drawText( Float.toString((float) airflowSpeed), px-95 , py+40, ReadingPaint); 187 | ReadingPaint.setTextSize(45); 188 | canvas.drawText( "m/s" , px+15 , py+40, ReadingPaint); 189 | 190 | } 191 | } -------------------------------------------------------------------------------- /android-multiple-bluetooth-connections/ViewTutorialPart2-master/src/com/jayway/viewtutorial/part2/LayoutChangesActivity.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alanxuefei/android-multiple-bluetooth-connections/76739585c5a4ca374f248f8648dcab4c28ad10ae/android-multiple-bluetooth-connections/ViewTutorialPart2-master/src/com/jayway/viewtutorial/part2/LayoutChangesActivity.java -------------------------------------------------------------------------------- /android-multiple-bluetooth-connections/ViewTutorialPart2-master/src/com/jayway/viewtutorial/part2/LineChartView.java: -------------------------------------------------------------------------------- 1 | package com.jayway.viewtutorial.part2; 2 | 3 | import android.content.Context; 4 | import android.graphics.Canvas; 5 | import android.graphics.Color; 6 | import android.graphics.CornerPathEffect; 7 | import android.graphics.Paint; 8 | import android.graphics.Paint.Style; 9 | import android.graphics.Path; 10 | import android.util.AttributeSet; 11 | import android.util.FloatMath; 12 | import android.view.View; 13 | 14 | 15 | public class LineChartView extends View { 16 | 17 | private static final int MIN_LINES = 4; 18 | private static final int MAX_LINES = 7; 19 | private static final int[] DISTANCES = { 1, 2, 5 }; 20 | 21 | private float[] datapoints = new float[] {}; 22 | private Paint paint = new Paint(); 23 | 24 | public LineChartView(Context context, AttributeSet attrs) { 25 | super(context, attrs); 26 | } 27 | 28 | /** 29 | * Sets the y data points of the line chart. The data points are assumed to 30 | * be positive and equally spaced on the x-axis. The line chart will be 31 | * scaled so that the entire height of the view is used. 32 | * 33 | * @param datapoints 34 | * y values of the line chart 35 | */ 36 | public void setChartData(float[] datapoints) { 37 | this.datapoints = datapoints.clone(); 38 | invalidate(); 39 | } 40 | 41 | @Override 42 | protected void onDraw(Canvas canvas) { 43 | //drawBackground(canvas); 44 | drawLineChart(canvas); 45 | } 46 | 47 | private void drawBackground(Canvas canvas) { 48 | float maxValue = getMax(datapoints); 49 | int range = getLineDistance(maxValue); 50 | 51 | paint.setStyle(Style.STROKE); 52 | paint.setColor(Color.GRAY); 53 | for (int y = 0; y < maxValue; y += range) { 54 | final float yPos = getYPos(y); 55 | canvas.drawLine(0, yPos, getWidth(), yPos, paint); 56 | } 57 | } 58 | 59 | private int getLineDistance(float maxValue) { 60 | int distance; 61 | int distanceIndex = 0; 62 | int distanceMultiplier = 1; 63 | int numberOfLines = MIN_LINES; 64 | 65 | do { 66 | distance = DISTANCES[distanceIndex] * distanceMultiplier; 67 | numberOfLines = (int) FloatMath.ceil(maxValue / distance); 68 | 69 | distanceIndex++; 70 | if (distanceIndex == DISTANCES.length) { 71 | distanceIndex = 0; 72 | distanceMultiplier *= 10; 73 | } 74 | } while (numberOfLines < MIN_LINES || numberOfLines > MAX_LINES); 75 | 76 | return distance; 77 | } 78 | 79 | private void drawLineChart(Canvas canvas) { 80 | Path path = new Path(); 81 | path.moveTo(getXPos(0), getYPos(datapoints[0])); 82 | for (int i = 1; i < datapoints.length; i++) { 83 | path.lineTo(getXPos(i), getYPos(datapoints[i])); 84 | } 85 | 86 | paint.setStyle(Style.STROKE); 87 | paint.setStrokeWidth(4); 88 | paint.setColor(Color.WHITE); 89 | paint.setAntiAlias(true); 90 | paint.setShadowLayer(4, 2, 2, 0x80000000); 91 | paint.setDither(true); // set the dither to true 92 | paint.setStyle(Paint.Style.STROKE); // set to STOKE 93 | paint.setStrokeJoin(Paint.Join.ROUND); // set the join to round you want 94 | paint.setStrokeCap(Paint.Cap.ROUND); // set the paint cap to round too 95 | paint.setPathEffect(new CornerPathEffect(10) ); // set the path effect when they join. 96 | paint.setAntiAlias(true); // set anti alias so it smooths 97 | 98 | 99 | canvas.drawPath(path, paint); 100 | paint.setShadowLayer(0, 0, 0, 0); 101 | } 102 | 103 | private float getMax(float[] array) { 104 | float max = array[0]; 105 | for (int i = 1; i < array.length; i++) { 106 | if (array[i] > max) { 107 | max = array[i]; 108 | } 109 | } 110 | return max; 111 | } 112 | 113 | private float getYPos(float value) { 114 | float height = getHeight() - getPaddingTop() - getPaddingBottom(); 115 | float maxValue = getMax(datapoints); 116 | 117 | // scale it to the view size 118 | value = (value / maxValue) * height; 119 | 120 | // invert it so that higher values have lower y 121 | value = height - value; 122 | 123 | // offset it to adjust for padding 124 | value += getPaddingTop(); 125 | 126 | return value; 127 | } 128 | 129 | private float getXPos(float value) { 130 | float width = getWidth() - getPaddingLeft() - getPaddingRight(); 131 | float maxValue = datapoints.length - 1; 132 | 133 | // scale it to the view size 134 | value = (value / maxValue) * width; 135 | 136 | // offset it to adjust for padding 137 | value += getPaddingLeft(); 138 | 139 | return value; 140 | } 141 | 142 | } 143 | -------------------------------------------------------------------------------- /android-multiple-bluetooth-connections/ViewTutorialPart2-master/src/com/jayway/viewtutorial/part2/MyService0.java: -------------------------------------------------------------------------------- 1 | package com.jayway.viewtutorial.part2; 2 | 3 | import java.util.Random; 4 | 5 | import android.app.Service; 6 | import android.content.Intent; 7 | import android.os.Handler; 8 | import android.os.IBinder; 9 | import android.util.Log; 10 | import android.widget.Toast; 11 | 12 | public class MyService0 extends Service{ 13 | 14 | public static float floatArray[] = { 1, 1, 1, 1, 1, 1, 15 | 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1,}; 16 | 17 | public static int Direction; 18 | public static float Speed ; 19 | private static final String TAG = "MyService"; 20 | 21 | Handler handler = new Handler(); 22 | Runnable runnable = new Runnable() { 23 | public void run() { 24 | afficher(); 25 | } 26 | }; 27 | 28 | 29 | public void afficher() 30 | { 31 | 32 | Random rand = new Random(); 33 | 34 | // nextInt is normally exclusive of the top value, 35 | // so add 1 to make it inclusive 36 | float randomNum = rand.nextInt(80); 37 | randomNum = randomNum/10; 38 | 39 | for(int a = 0; a < floatArray.length-1; a++){ 40 | floatArray[a]=floatArray[a+1]; 41 | } 42 | floatArray[floatArray.length-1]=randomNum; 43 | rand = new Random(); 44 | 45 | Speed=randomNum; 46 | Direction= rand.nextInt((360 - 0) + 1) + 1; 47 | handler.postDelayed(runnable, 1000); 48 | } 49 | 50 | @Override 51 | public IBinder onBind(Intent arg0) { 52 | return null; 53 | } 54 | 55 | @Override 56 | public void onCreate() { 57 | 58 | //Toast.makeText(this, "Airflow Sensor One Is Connected", Toast.LENGTH_LONG).show(); 59 | Log.d(TAG, "onCreate"); 60 | } 61 | 62 | @Override 63 | public void onStart(Intent intent, int startId) { 64 | Toast.makeText(this, "Airflow Sensor One ", Toast.LENGTH_LONG).show(); 65 | Log.d(TAG, "onStart"); 66 | runnable.run(); 67 | } 68 | 69 | @Override 70 | public void onDestroy() { 71 | Toast.makeText(this, "Airflow Sensor One Is Removed", Toast.LENGTH_LONG).show(); 72 | Log.d(TAG, "onDestroy"); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /android-multiple-bluetooth-connections/ViewTutorialPart2-master/src/com/jayway/viewtutorial/part2/MyService1.java: -------------------------------------------------------------------------------- 1 | package com.jayway.viewtutorial.part2; 2 | 3 | import android.app.Service; 4 | import android.content.Intent; 5 | import android.os.Handler; 6 | import android.os.IBinder; 7 | import android.util.Log; 8 | import android.widget.Toast; 9 | import java.util.Timer; 10 | import java.util.TimerTask; 11 | import java.util.UUID; 12 | import java.io.IOException; 13 | import java.io.InputStream; 14 | import java.io.OutputStream; 15 | import java.lang.reflect.Method; 16 | import android.os.Build; 17 | import android.bluetooth.BluetoothAdapter; 18 | import android.bluetooth.BluetoothDevice; 19 | import android.bluetooth.BluetoothSocket; 20 | 21 | public class MyService1 extends Service{ 22 | 23 | Timer t; 24 | TimerTask task; 25 | 26 | /*** Bluetooth 1 ***/ 27 | 28 | private BluetoothAdapter btAdapter = null; 29 | private BluetoothSocket btSocket = null; 30 | private StringBuilder sb = new StringBuilder(); 31 | 32 | private ConnectedThread mConnectedThread; 33 | 34 | // SPP UUID service 35 | private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); 36 | 37 | // MAC-address of Bluetooth module (you must edit this line) 38 | // private static String address = "00:06:66:4E:3E:BD"; 39 | private static String address = "98:D3:31:B2:00:14"; 40 | 41 | 42 | 43 | /*** Bluetooth ***/ 44 | 45 | public static float floatArray[] = { 1, 1, 1, 1, 1, 1, 46 | 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1,}; 47 | 48 | public static int Direction; 49 | public static float Speed ; 50 | private static final String TAG = "MyService"; 51 | 52 | Handler handler = new Handler(); 53 | Runnable runnable = new Runnable() { 54 | public void run() { 55 | afficher(); 56 | } 57 | }; 58 | 59 | 60 | public void afficher() 61 | { 62 | for(int a = 0; a < floatArray.length-1; a++){ 63 | floatArray[a]=floatArray[a+1]; 64 | } 65 | floatArray[floatArray.length-1]=Speed; 66 | handler.postDelayed(runnable, 1000); 67 | } 68 | 69 | @Override 70 | public IBinder onBind(Intent arg0) { 71 | return null; 72 | } 73 | 74 | @Override 75 | public void onCreate() { 76 | 77 | // Toast.makeText(this, "Airflow Sensor Three Is Connected", Toast.LENGTH_LONG).show(); 78 | Log.d(TAG, "onCreate"); 79 | 80 | } 81 | 82 | @Override 83 | public void onStart(Intent intent, int startId) { 84 | Toast.makeText(this, "Airflow Sensor Three Is Connected", Toast.LENGTH_LONG).show(); 85 | Log.d(TAG, "onStart"); 86 | startMeasureResult(); 87 | runnable.run(); 88 | } 89 | 90 | @Override 91 | public void onDestroy() { 92 | Toast.makeText(this, "Airflow Sensor Three Is Removed", Toast.LENGTH_LONG).show(); 93 | Log.d(TAG, "onDestroy"); 94 | } 95 | 96 | 97 | public void startMeasureResult() { 98 | /*bluetooth2*/ 99 | 100 | btAdapter = BluetoothAdapter.getDefaultAdapter(); // get Bluetooth adapter 101 | 102 | 103 | 104 | // Set up a pointer to the remote node using it's address. 105 | BluetoothDevice device = btAdapter.getRemoteDevice(address); 106 | 107 | // Two things are needed to make a connection: 108 | // A MAC address, which we got above. 109 | // A Service ID or UUID. In this case we are using the 110 | // UUID for SPP. 111 | 112 | try { 113 | btSocket = createBluetoothSocket(device); 114 | } catch (IOException e) { 115 | errorExit("Fatal Error", "In onResume() and socket create failed: " + e.getMessage() + "."); 116 | } 117 | 118 | 119 | 120 | // Discovery is resource intensive. Make sure it isn't going on 121 | // when you attempt to connect and pass your message. 122 | btAdapter.cancelDiscovery(); 123 | 124 | // Establish the connection. This will block until it connects. 125 | Log.d("bluetooth", "...Connecting..."); 126 | // Toast.makeText(MicroAnemometerActivity.this, "Bluetooth ...Connecting...", Toast.LENGTH_SHORT).show(); 127 | try { 128 | btSocket.connect(); 129 | Log.d("bluetooth", "....Connection ok..."); 130 | //Toast.makeText(MicroAnemometerActivity.this, "Bluetooth ....Connection ok...", Toast.LENGTH_SHORT).show(); 131 | } catch (IOException e) { 132 | try { 133 | btSocket.close(); 134 | } catch (IOException e2) { 135 | errorExit("Fatal Error", "In onResume() and unable to close socket during connection failure" + e2.getMessage() + "."); 136 | } 137 | } 138 | 139 | // Create a data stream so we can talk to server. 140 | Log.d("bluetooth", "...Create Socket..."); 141 | 142 | mConnectedThread = new ConnectedThread(btSocket); 143 | mConnectedThread.start(); 144 | } 145 | 146 | 147 | 148 | 149 | private BluetoothSocket createBluetoothSocket(BluetoothDevice device) throws IOException { 150 | if(Build.VERSION.SDK_INT >= 10){ 151 | try { 152 | final Method m = device.getClass().getMethod("createInsecureRfcommSocketToServiceRecord", new Class[] { UUID.class }); 153 | return (BluetoothSocket) m.invoke(device, MY_UUID); 154 | } catch (Exception e) { 155 | // Log.e(TAG, "Could not create Insecure RFComm Connection",e); 156 | } 157 | } 158 | return device.createRfcommSocketToServiceRecord(MY_UUID); 159 | } 160 | 161 | public void setMeasureResult(String str) { 162 | int index1=-1; 163 | int index2=-1; 164 | int index3=-1; 165 | String str3,str2="0"; 166 | 167 | //Speed++; 168 | //index1 = str.lastIndexOf("sensor = "); 169 | index2 = str.lastIndexOf("end"); 170 | if (index2!=-1){ 171 | str3=str.substring(0, index2); 172 | index1 = str3.lastIndexOf("Direction"); 173 | if ((index2>index1+1)&&(index2!=-1)&&(index1!=-1)){ 174 | str2=str.substring(index1+9, index2); 175 | Direction=Integer.parseInt(str2); 176 | 177 | } 178 | index3 = str3.lastIndexOf("Speed"); 179 | if ((index1>index3+1)&&(index1!=-1)&&(index3!=-1)){ 180 | str2=str.substring(index3+5, index1); 181 | 182 | Speed=Float.parseFloat(str2); 183 | } 184 | } 185 | } 186 | 187 | 188 | 189 | private void checkBTState() { 190 | // Check for Bluetooth support and then check to make sure it is turned on 191 | // Emulator doesn't support Bluetooth and will return null 192 | 193 | if(btAdapter==null) { 194 | 195 | // errorExit("Fatal Error", "Bluetooth 2"); 196 | } else { 197 | if (btAdapter.isEnabled()) { 198 | 199 | } else { 200 | 201 | //Prompt user to turn on Bluetooth 202 | // Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); 203 | //startActivityForResult(enableBtIntent, 1); 204 | } 205 | } 206 | } 207 | 208 | private void errorExit(String title, String message){ 209 | Toast.makeText(getBaseContext(), title + " - " + message, Toast.LENGTH_LONG).show(); 210 | 211 | } 212 | 213 | private class ConnectedThread extends Thread { 214 | private final InputStream mmInStream; 215 | private final OutputStream mmOutStream; 216 | 217 | public ConnectedThread(BluetoothSocket socket) { 218 | InputStream tmpIn = null; 219 | OutputStream tmpOut = null; 220 | 221 | // Get the input and output streams, using temp objects because 222 | // member streams are final 223 | try { 224 | tmpIn = socket.getInputStream(); 225 | tmpOut = socket.getOutputStream(); 226 | } catch (IOException e) { } 227 | 228 | mmInStream = tmpIn; 229 | mmOutStream = tmpOut; 230 | } 231 | 232 | public void run() { 233 | byte[] buffer = new byte[256]; // buffer store for the stream 234 | int bytes; // bytes returned from read() 235 | 236 | // Keep listening to the InputStream until an exception occurs 237 | while (true) { 238 | try { 239 | // Read from the InputStream 240 | bytes = mmInStream.read(buffer); // Get number of bytes and messan "buffer" 241 | String readMessage = new String(buffer, 0, bytes); 242 | sb.append(readMessage); 243 | int endOfLineIndex = sb.indexOf("\r\n"); 244 | if (endOfLineIndex > 0) { // if end-of-line, 245 | String sbprint = sb.substring(0, endOfLineIndex); // extract string 246 | 247 | setMeasureResult(sbprint);// update TextView 248 | sb.delete(0, sb.length()); // and clear 249 | 250 | 251 | 252 | Log.d("xuefei", sbprint); 253 | } 254 | 255 | 256 | } catch (IOException e) { 257 | break; 258 | } 259 | } 260 | } 261 | 262 | 263 | } 264 | } 265 | -------------------------------------------------------------------------------- /android-multiple-bluetooth-connections/ViewTutorialPart2-master/src/com/jayway/viewtutorial/part2/MyService2.java: -------------------------------------------------------------------------------- 1 | package com.jayway.viewtutorial.part2; 2 | 3 | import android.app.Service; 4 | import android.content.Intent; 5 | import android.os.Handler; 6 | import android.os.IBinder; 7 | import android.util.Log; 8 | import android.widget.Toast; 9 | import java.util.Timer; 10 | import java.util.TimerTask; 11 | import java.util.UUID; 12 | import java.io.IOException; 13 | import java.io.InputStream; 14 | import java.io.OutputStream; 15 | import java.lang.reflect.Method; 16 | import android.os.Build; 17 | import android.bluetooth.BluetoothAdapter; 18 | import android.bluetooth.BluetoothDevice; 19 | import android.bluetooth.BluetoothSocket; 20 | 21 | public class MyService2 extends Service{ 22 | 23 | Timer t; 24 | TimerTask task; 25 | 26 | /*** Bluetooth 1 ***/ 27 | 28 | private BluetoothAdapter btAdapter = null; 29 | private BluetoothSocket btSocket = null; 30 | private StringBuilder sb = new StringBuilder(); 31 | 32 | private ConnectedThread mConnectedThread; 33 | 34 | // SPP UUID service 35 | private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); 36 | 37 | // MAC-address of Bluetooth module (you must edit this line) 38 | private static String address = "00:06:66:4E:3E:BD"; 39 | //private static String address = "98:D3:31:B2:00:14"; 40 | 41 | 42 | 43 | /*** Bluetooth ***/ 44 | 45 | public static float floatArray[] = { 1, 1, 1, 1, 1, 1, 46 | 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1,}; 47 | 48 | public static int Direction; 49 | public static float Speed ; 50 | private static final String TAG = "MyService"; 51 | 52 | Handler handler = new Handler(); 53 | Runnable runnable = new Runnable() { 54 | public void run() { 55 | afficher(); 56 | } 57 | }; 58 | 59 | 60 | public void afficher() 61 | { 62 | for(int a = 0; a < floatArray.length-1; a++){ 63 | floatArray[a]=floatArray[a+1]; 64 | } 65 | floatArray[floatArray.length-1]=Speed; 66 | handler.postDelayed(runnable, 1000); 67 | } 68 | 69 | @Override 70 | public IBinder onBind(Intent arg0) { 71 | return null; 72 | } 73 | 74 | @Override 75 | public void onCreate() { 76 | 77 | // Toast.makeText(this, "Airflow Sensor Three Is Connected", Toast.LENGTH_LONG).show(); 78 | Log.d(TAG, "onCreate"); 79 | 80 | } 81 | 82 | @Override 83 | public void onStart(Intent intent, int startId) { 84 | Toast.makeText(this, "Airflow Sensor Three Is Connected", Toast.LENGTH_LONG).show(); 85 | Log.d(TAG, "onStart"); 86 | startMeasureResult(); 87 | runnable.run(); 88 | } 89 | 90 | @Override 91 | public void onDestroy() { 92 | Toast.makeText(this, "Airflow Sensor Three Is Removed", Toast.LENGTH_LONG).show(); 93 | Log.d(TAG, "onDestroy"); 94 | } 95 | 96 | 97 | public void startMeasureResult() { 98 | /*bluetooth2*/ 99 | 100 | btAdapter = BluetoothAdapter.getDefaultAdapter(); // get Bluetooth adapter 101 | 102 | 103 | 104 | // Set up a pointer to the remote node using it's address. 105 | BluetoothDevice device = btAdapter.getRemoteDevice(address); 106 | 107 | // Two things are needed to make a connection: 108 | // A MAC address, which we got above. 109 | // A Service ID or UUID. In this case we are using the 110 | // UUID for SPP. 111 | 112 | try { 113 | btSocket = createBluetoothSocket(device); 114 | } catch (IOException e) { 115 | errorExit("Fatal Error", "In onResume() and socket create failed: " + e.getMessage() + "."); 116 | } 117 | 118 | 119 | 120 | // Discovery is resource intensive. Make sure it isn't going on 121 | // when you attempt to connect and pass your message. 122 | btAdapter.cancelDiscovery(); 123 | 124 | // Establish the connection. This will block until it connects. 125 | Log.d("bluetooth", "...Connecting..."); 126 | // Toast.makeText(MicroAnemometerActivity.this, "Bluetooth ...Connecting...", Toast.LENGTH_SHORT).show(); 127 | try { 128 | btSocket.connect(); 129 | Log.d("bluetooth", "....Connection ok..."); 130 | //Toast.makeText(MicroAnemometerActivity.this, "Bluetooth ....Connection ok...", Toast.LENGTH_SHORT).show(); 131 | } catch (IOException e) { 132 | try { 133 | btSocket.close(); 134 | } catch (IOException e2) { 135 | errorExit("Fatal Error", "In onResume() and unable to close socket during connection failure" + e2.getMessage() + "."); 136 | } 137 | } 138 | 139 | // Create a data stream so we can talk to server. 140 | Log.d("bluetooth", "...Create Socket..."); 141 | 142 | mConnectedThread = new ConnectedThread(btSocket); 143 | mConnectedThread.start(); 144 | } 145 | 146 | 147 | 148 | 149 | private BluetoothSocket createBluetoothSocket(BluetoothDevice device) throws IOException { 150 | if(Build.VERSION.SDK_INT >= 10){ 151 | try { 152 | final Method m = device.getClass().getMethod("createInsecureRfcommSocketToServiceRecord", new Class[] { UUID.class }); 153 | return (BluetoothSocket) m.invoke(device, MY_UUID); 154 | } catch (Exception e) { 155 | // Log.e(TAG, "Could not create Insecure RFComm Connection",e); 156 | } 157 | } 158 | return device.createRfcommSocketToServiceRecord(MY_UUID); 159 | } 160 | 161 | public void setMeasureResult(String str) { 162 | int index1=-1; 163 | int index2=-1; 164 | int index3=-1; 165 | String str3,str2="0"; 166 | 167 | //Speed++; 168 | //index1 = str.lastIndexOf("sensor = "); 169 | index2 = str.lastIndexOf("end"); 170 | if (index2!=-1){ 171 | str3=str.substring(0, index2); 172 | index1 = str3.lastIndexOf("Direction"); 173 | if ((index2>index1+1)&&(index2!=-1)&&(index1!=-1)){ 174 | str2=str.substring(index1+9, index2); 175 | Direction=Integer.parseInt(str2); 176 | 177 | } 178 | index3 = str3.lastIndexOf("Speed"); 179 | if ((index1>index3+1)&&(index1!=-1)&&(index3!=-1)){ 180 | str2=str.substring(index3+5, index1); 181 | 182 | Speed=Float.parseFloat(str2); 183 | } 184 | } 185 | } 186 | 187 | 188 | 189 | private void checkBTState() { 190 | // Check for Bluetooth support and then check to make sure it is turned on 191 | // Emulator doesn't support Bluetooth and will return null 192 | 193 | if(btAdapter==null) { 194 | 195 | // errorExit("Fatal Error", "Bluetooth 2"); 196 | } else { 197 | if (btAdapter.isEnabled()) { 198 | 199 | } else { 200 | 201 | //Prompt user to turn on Bluetooth 202 | // Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); 203 | //startActivityForResult(enableBtIntent, 1); 204 | } 205 | } 206 | } 207 | 208 | private void errorExit(String title, String message){ 209 | Toast.makeText(getBaseContext(), title + " - " + message, Toast.LENGTH_LONG).show(); 210 | 211 | } 212 | 213 | private class ConnectedThread extends Thread { 214 | private final InputStream mmInStream; 215 | private final OutputStream mmOutStream; 216 | 217 | public ConnectedThread(BluetoothSocket socket) { 218 | InputStream tmpIn = null; 219 | OutputStream tmpOut = null; 220 | 221 | // Get the input and output streams, using temp objects because 222 | // member streams are final 223 | try { 224 | tmpIn = socket.getInputStream(); 225 | tmpOut = socket.getOutputStream(); 226 | } catch (IOException e) { } 227 | 228 | mmInStream = tmpIn; 229 | mmOutStream = tmpOut; 230 | } 231 | 232 | public void run() { 233 | byte[] buffer = new byte[256]; // buffer store for the stream 234 | int bytes; // bytes returned from read() 235 | 236 | // Keep listening to the InputStream until an exception occurs 237 | while (true) { 238 | try { 239 | // Read from the InputStream 240 | bytes = mmInStream.read(buffer); // Get number of bytes and messan "buffer" 241 | String readMessage = new String(buffer, 0, bytes); 242 | sb.append(readMessage); 243 | int endOfLineIndex = sb.indexOf("\r\n"); 244 | if (endOfLineIndex > 0) { // if end-of-line, 245 | String sbprint = sb.substring(0, endOfLineIndex); // extract string 246 | 247 | setMeasureResult(sbprint);// update TextView 248 | sb.delete(0, sb.length()); // and clear 249 | 250 | 251 | 252 | Log.d("xuefei", sbprint); 253 | } 254 | 255 | 256 | } catch (IOException e) { 257 | break; 258 | } 259 | } 260 | } 261 | 262 | 263 | } 264 | } 265 | -------------------------------------------------------------------------------- /android-multiple-bluetooth-connections/ViewTutorialPart2-master/src/com/jayway/viewtutorial/part2/ViewTutorialActivity.java: -------------------------------------------------------------------------------- 1 | package com.jayway.viewtutorial.part2; 2 | 3 | import java.util.Random; 4 | import java.util.Timer; 5 | import java.util.TimerTask; 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | import android.app.Activity; 15 | import android.app.AlertDialog; 16 | import android.content.DialogInterface; 17 | import android.content.Intent; 18 | import android.os.Bundle; 19 | import android.os.Handler; 20 | import android.util.Log; 21 | import android.view.Menu; 22 | import android.view.MenuItem; 23 | import android.view.View; 24 | import android.widget.ArrayAdapter; 25 | 26 | public class ViewTutorialActivity extends Activity { 27 | /** Called when the activity is first created. */ 28 | public static float floatArray[] = { 1, 1, 1, 1, 1, 1, 29 | 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1}; 30 | 31 | //private float floatArray2[] = { 13, 14, 15, 16, 17, 18, 19, 0, 2, 14, 12, 1, 13, 15 }; 32 | private LineChartView lineChart ; 33 | private DirectionView cv; 34 | private int randomNum2=15; 35 | 36 | //public String SensorID; 37 | 38 | Handler handler = new Handler(); 39 | Runnable runnable = new Runnable() { 40 | public void run() { 41 | afficher(); 42 | } 43 | }; 44 | 45 | @Override 46 | public void onCreate(Bundle savedInstanceState) { 47 | super.onCreate(savedInstanceState); 48 | setContentView(R.layout.main); 49 | 50 | lineChart = (LineChartView)findViewById(R.id.linechart); 51 | cv= (DirectionView)findViewById(R.id.Direction); 52 | runnable.run(); 53 | 54 | 55 | 56 | 57 | } 58 | 59 | @Override 60 | public boolean onCreateOptionsMenu(Menu menu) { 61 | super.onCreateOptionsMenu(menu); 62 | getMenuInflater().inflate(R.layout.view_sub, menu); 63 | return true; 64 | } 65 | 66 | @Override 67 | public boolean onOptionsItemSelected(MenuItem item) { 68 | 69 | ArrayAdapter mArrayAdapter = null; 70 | switch (item.getItemId()) { 71 | case android.R.id.home: 72 | // Navigate "up" the demo structure to the launchpad activity. 73 | // See http://developer.android.com/design/patterns/navigation.html for more. 74 | //NavUtils.navigateUpTo(this, new Intent(this, ViewTutorialActivity.class)); 75 | return true; 76 | 77 | case R.id.action_add_item: 78 | //Intent nextScreen = new Intent(getApplicationContext(), LayoutChangesActivity.class); 79 | //startActivity(nextScreen); 80 | // return true; 81 | finish(); 82 | } 83 | 84 | return super.onOptionsItemSelected(item); 85 | } 86 | 87 | public void afficher() 88 | { 89 | Intent i = getIntent(); 90 | String SensorID = i.getStringExtra("SensorID"); 91 | Random rand = new Random(); 92 | Log.e("tag" ,SensorID); 93 | 94 | if (SensorID.compareTo("Sensor One")==0){ 95 | lineChart.setChartData(MyService0.floatArray); 96 | Log.e("tag" ,"Here1"); 97 | cv.setBearing(MyService0.Direction,MyService0.Speed); 98 | } 99 | else 100 | { 101 | if (SensorID.compareTo("Sensor Two")==0){ 102 | lineChart.setChartData(MyService1.floatArray); 103 | cv.setBearing(MyService1.Direction,MyService1.Speed); 104 | Log.e("tag" ,"Here2"); 105 | } 106 | else { 107 | if (SensorID.compareTo("Sensor Three")==0){ 108 | lineChart.setChartData(MyService2.floatArray); 109 | cv.setBearing(MyService2.Direction,MyService2.Speed); 110 | Log.e("tag" ,"Here3"); 111 | } 112 | else { 113 | lineChart.setChartData(MyService0.floatArray); 114 | } 115 | } 116 | } 117 | 118 | 119 | // nextInt is normally exclusive of the top value, 120 | // so add 1 to make it inclusive 121 | // float randomNum = MyService2.Speed; 122 | 123 | // for(int a = 0; a < floatArray.length-1; a++){ 124 | // floatArray[a]=floatArray[a+1]; 125 | // } 126 | // floatArray[floatArray.length-1]=randomNum; 127 | 128 | 129 | // rand = new Random(); 130 | // lineChart.setChartData(floatArray); 131 | 132 | 133 | // cv.setBearing(randomNum2++,randomNum); 134 | 135 | handler.postDelayed(runnable, 1000); 136 | } 137 | 138 | 139 | } --------------------------------------------------------------------------------