11package io .pslab .activity ;
22
33import android .annotation .SuppressLint ;
4+ import android .content .DialogInterface ;
45import android .content .SharedPreferences ;
56import android .graphics .Color ;
67import android .hardware .Sensor ;
1112import android .os .Handler ;
1213import android .support .annotation .NonNull ;
1314import android .support .design .widget .BottomSheetBehavior ;
15+ import android .support .v7 .app .AlertDialog ;
1416import android .support .v7 .app .AppCompatActivity ;
1517import android .os .Bundle ;
1618import android .view .GestureDetector ;
4749import butterknife .ButterKnife ;
4850import butterknife .Unbinder ;
4951
50- public class Barometer_activity extends AppCompatActivity {
52+ public class BarometerActivity extends AppCompatActivity {
5153 BottomSheetBehavior bottomSheetBehavior ;
5254 GestureDetector gestureDetector ;
5355 private static final String PREF_NAME = "customDialogPreference" ;
5456
5557 private static int sensorType = 0 ;
5658 private static int highLimit = 1000 ;
5759 private static int updatePeriod = 100 ;
58- private Barometer_activity .SensorDataFetch sensorDataFetch ;
60+ private BarometerActivity .SensorDataFetch sensorDataFetch ;
5961
6062 @ BindView (R .id .barometer_max )
6163 TextView statMax ;
@@ -101,8 +103,8 @@ public class Barometer_activity extends AppCompatActivity {
101103 @ BindView (R .id .custom_dialog_desc )
102104 TextView bottomSheetDesc ;
103105
104- public static Barometer_activity newInstance () {
105- return new Barometer_activity ();
106+ public static BarometerActivity newInstance () {
107+ return new BarometerActivity ();
106108 }
107109
108110 @ SuppressLint ("ResourceType" )
@@ -112,14 +114,33 @@ protected void onCreate(Bundle savedInstanceState) {
112114 setContentView (R .layout .activity_barometer_main );
113115 ButterKnife .bind (this );
114116 setUpBottomSheet ();
115- Barometer_activity .newInstance ();
117+ BarometerActivity .newInstance ();
116118
117119 currentMin = 10000 ;
118120 entries = new ArrayList <>();
119121 switch (sensorType ) {
120122 case 0 :
121123 sensorManager = (SensorManager ) getSystemService (SENSOR_SERVICE );
122124 sensor = sensorManager != null ? sensorManager .getDefaultSensor (Sensor .TYPE_PRESSURE ) : null ;
125+ if (sensor == null ) {
126+ runOnUiThread (new Runnable () {
127+ @ Override
128+ public void run () {
129+ if (!isFinishing ()) {
130+ new AlertDialog .Builder (BarometerActivity .this )
131+ .setTitle (R .string .barometer_alert_title )
132+ .setMessage (R .string .barometer_alert_description )
133+ .setCancelable (false )
134+ .setPositiveButton ("ok" , new DialogInterface .OnClickListener () {
135+ @ Override
136+ public void onClick (DialogInterface dialog , int which ) {
137+ dialog .dismiss ();
138+ }
139+ }).show ();
140+ }
141+ }
142+ });
143+ }
123144 break ;
124145 case 1 :
125146 scienceLab = ScienceLabCommon .scienceLab ;
@@ -228,9 +249,9 @@ public void run() {
228249 }
229250
230251 public static void setParameters (int sensorType , int highLimit , int updatePeriod ) {
231- Barometer_activity .sensorType = sensorType ;
232- Barometer_activity .highLimit = highLimit ;
233- Barometer_activity .updatePeriod = updatePeriod ;
252+ BarometerActivity .sensorType = sensorType ;
253+ BarometerActivity .highLimit = highLimit ;
254+ BarometerActivity .updatePeriod = updatePeriod ;
234255 }
235256
236257
0 commit comments