From 78acf822bc9e14afb2dc668c786902eedc765a1e Mon Sep 17 00:00:00 2001 From: rajat <42169801+imrajat7@users.noreply.github.com> Date: Sun, 7 Oct 2018 01:03:56 +0530 Subject: [PATCH 1/7] Hard Coded dimensions fixed in splash screen (#1406) --- app/src/main/res/layout/splash_screen.xml | 10 +++++----- app/src/main/res/values/dimens.xml | 3 +++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/src/main/res/layout/splash_screen.xml b/app/src/main/res/layout/splash_screen.xml index e1e8e8694..1c0ef9a71 100644 --- a/app/src/main/res/layout/splash_screen.xml +++ b/app/src/main/res/layout/splash_screen.xml @@ -9,14 +9,14 @@ + android:layout_height="@dimen/splash_screen_logo_height" + android:contentDescription="@string/pocket_science_logo" + android:src="@drawable/logo" /> diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 9a553146e..c8a31c378 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -382,5 +382,8 @@ 5dp 200dp 5dp + 314dp + 271dp + 95dp From 10ac9346694f9bf0a11f605e3a16d2cd5be49b3f Mon Sep 17 00:00:00 2001 From: Avjeet Date: Sun, 21 Oct 2018 12:18:49 +0530 Subject: [PATCH 2/7] resolved empty data bug in lux meter (#1401) some minor chages --- .../io/pslab/activity/LuxMeterActivity.java | 13 ++-- .../pslab/fragment/LuxMeterFragmentData.java | 62 ++++++++++--------- .../main/java/io/pslab/others/GPSLogger.java | 2 +- app/src/main/res/values/strings.xml | 1 + 4 files changed, 44 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/io/pslab/activity/LuxMeterActivity.java b/app/src/main/java/io/pslab/activity/LuxMeterActivity.java index 6d7d63200..14732ae75 100644 --- a/app/src/main/java/io/pslab/activity/LuxMeterActivity.java +++ b/app/src/main/java/io/pslab/activity/LuxMeterActivity.java @@ -201,11 +201,14 @@ public boolean onOptionsItemSelected(MenuItem item) { ((LuxMeterFragmentData) selectedFragment).stopSensorFetching(); invalidateOptionsMenu(); Long uniqueRef = realmPreferences.getLong("uniqueCount", 0); - selectedFragment.saveDataInRealm(uniqueRef, locationPref, gpsLogger); - CustomSnackBar.showSnackBar(coordinatorLayout, getString(R.string.exp_data_saved), null, null); - SharedPreferences.Editor editor = realmPreferences.edit(); - editor.putLong("uniqueCount", uniqueRef + 1); - editor.commit(); + if (selectedFragment.saveDataInRealm(uniqueRef, locationPref, gpsLogger)) { + CustomSnackBar.showSnackBar(coordinatorLayout, getString(R.string.exp_data_saved), null, null); + SharedPreferences.Editor editor = realmPreferences.edit(); + editor.putLong("uniqueCount", uniqueRef + 1); + editor.commit(); + } else { + CustomSnackBar.showSnackBar(coordinatorLayout, getString(R.string.no_data_fetched), null, null); + } recordData = false; } else { if (locationPref) { diff --git a/app/src/main/java/io/pslab/fragment/LuxMeterFragmentData.java b/app/src/main/java/io/pslab/fragment/LuxMeterFragmentData.java index 027060581..bcb1d2470 100644 --- a/app/src/main/java/io/pslab/fragment/LuxMeterFragmentData.java +++ b/app/src/main/java/io/pslab/fragment/LuxMeterFragmentData.java @@ -400,40 +400,46 @@ public void stopSensorFetching() { } } - public void saveDataInRealm(Long uniqueRef, boolean includeLocation, GPSLogger gpsLogger) { - realm.beginTransaction(); - - SensorLogged sensorLogged = realm.createObject(SensorLogged.class, uniqueRef); - sensorLogged.setSensor("Lux Meter"); - sensorLogged.setDateTimeStart(startTime); - sensorLogged.setDateTimeEnd(endTime); - sensorLogged.setTimeZone(TimeZone.getDefault().getDisplayName()); - - if (includeLocation && gpsLogger != null) { - Location location = gpsLogger.getBestLocation(); - if (location != null) { - sensorLogged.setLatitude(location.getLatitude()); - sensorLogged.setLongitude(location.getLongitude()); + public boolean saveDataInRealm(Long uniqueRef, boolean includeLocation, GPSLogger gpsLogger) { + boolean flag = luxRealmData.isEmpty(); + if (!flag) { + realm.beginTransaction(); + + SensorLogged sensorLogged = realm.createObject(SensorLogged.class, uniqueRef); + sensorLogged.setSensor(getResources().getString(R.string.lux_meter)); + sensorLogged.setDateTimeStart(startTime); + sensorLogged.setDateTimeEnd(endTime); + sensorLogged.setTimeZone(TimeZone.getDefault().getDisplayName()); + + if (includeLocation && gpsLogger != null) { + Location location = gpsLogger.getBestLocation(); + if (location != null) { + sensorLogged.setLatitude(location.getLatitude()); + sensorLogged.setLongitude(location.getLongitude()); + } else { + sensorLogged.setLatitude(0.0); + sensorLogged.setLongitude(0.0); + } + gpsLogger.removeUpdate(); } else { sensorLogged.setLatitude(0.0); sensorLogged.setLongitude(0.0); } - gpsLogger.removeUpdate(); - } else { - sensorLogged.setLatitude(0.0); - sensorLogged.setLongitude(0.0); - } - for (int i = 0; i < luxRealmData.size(); i++) { - LuxData tempObject = luxRealmData.get(i); - tempObject.setId(i); - tempObject.setForeignKey(uniqueRef); - realm.copyToRealm(tempObject); - Log.i("dataResult", String.valueOf(tempObject.getLux())); + for (int i = 0; i < luxRealmData.size(); i++) { + LuxData tempObject = luxRealmData.get(i); + tempObject.setId(i); + tempObject.setForeignKey(uniqueRef); + realm.copyToRealm(tempObject); + Log.i("dataResult", String.valueOf(tempObject.getLux())); + } + realm.copyToRealm(sensorLogged); + realm.commitTransaction(); + luxRealmData.clear(); + return true; + } else { + return false; } - realm.copyToRealm(sensorLogged); - realm.commitTransaction(); - luxRealmData.clear(); } @Override diff --git a/app/src/main/java/io/pslab/others/GPSLogger.java b/app/src/main/java/io/pslab/others/GPSLogger.java index 4280b3119..040c7b1dd 100644 --- a/app/src/main/java/io/pslab/others/GPSLogger.java +++ b/app/src/main/java/io/pslab/others/GPSLogger.java @@ -26,7 +26,7 @@ public class GPSLogger { public static final int MY_PERMISSIONS_REQUEST_LOCATION = 99; - private static final int UPDATE_INTERVAL_IN_MILLISECONDS = 1000; + private static final int UPDATE_INTERVAL_IN_MILLISECONDS = 400; private static final int MIN_DISTANCE_CHANGE_FOR_UPDATES = 1; private LocationManager locationManager; private Context context; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8567cb33b..47e559c07 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1036,5 +1036,6 @@ GND. GND is meant for Ground and any of the PSLab device GND pins can be used since they are common.\n\n \u2022 Select sensor by going to the Configure tab from the bottom navigation bar and choose BHT-1750 in the drop down menu under Select Sensor.\n Lux Meter Settings + No Data Fetched From a66071f6fdafbb260bb0299f4b4cd756d7d2cec8 Mon Sep 17 00:00:00 2001 From: Harsh Patel Date: Sun, 21 Oct 2018 12:29:03 +0530 Subject: [PATCH 3/7] Solved bottom sheet overlapping issue in Barometer instrument (#1399) Solved major bugs in Barometer instrument Removed extra comments --- .../io/pslab/activity/BarometerActivity.java | 241 ++++++-------- .../io/pslab/fragment/BarometerFragment.java | 304 ------------------ .../main/res/layout/activity_barometer.xml | 262 +++++++++++++++ .../res/layout/activity_barometer_main.xml | 7 +- .../main/res/layout/fragment_barometer.xml | 267 --------------- 5 files changed, 369 insertions(+), 712 deletions(-) delete mode 100644 app/src/main/java/io/pslab/fragment/BarometerFragment.java delete mode 100644 app/src/main/res/layout/fragment_barometer.xml diff --git a/app/src/main/java/io/pslab/activity/BarometerActivity.java b/app/src/main/java/io/pslab/activity/BarometerActivity.java index cdef8eef5..657da8079 100644 --- a/app/src/main/java/io/pslab/activity/BarometerActivity.java +++ b/app/src/main/java/io/pslab/activity/BarometerActivity.java @@ -9,22 +9,20 @@ import android.hardware.SensorEventListener; import android.hardware.SensorManager; import android.os.AsyncTask; +import android.os.Bundle; import android.os.Handler; import android.support.annotation.NonNull; import android.support.design.widget.BottomSheetBehavior; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; -import android.os.Bundle; import android.view.GestureDetector; -import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; -import android.view.ViewGroup; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; -import com.github.anastr.speedviewlib.TubeSpeedometer; +import com.github.anastr.speedviewlib.PointerSpeedometer; import com.github.mikephil.charting.charts.LineChart; import com.github.mikephil.charting.components.Legend; import com.github.mikephil.charting.components.XAxis; @@ -33,13 +31,6 @@ import com.github.mikephil.charting.data.LineData; import com.github.mikephil.charting.data.LineDataSet; -import io.pslab.R; -import io.pslab.communication.ScienceLab; -import io.pslab.communication.sensors.BMP180; -import io.pslab.others.MathUtils; -import io.pslab.others.ScienceLabCommon; -import io.pslab.others.SwipeGestureDetector; - import java.io.IOException; import java.text.DecimalFormat; import java.util.ArrayList; @@ -48,17 +39,21 @@ import butterknife.BindView; import butterknife.ButterKnife; import butterknife.Unbinder; +import io.pslab.R; +import io.pslab.communication.ScienceLab; +import io.pslab.communication.sensors.BMP180; +import io.pslab.others.MathUtils; +import io.pslab.others.ScienceLabCommon; +import io.pslab.others.SwipeGestureDetector; public class BarometerActivity extends AppCompatActivity { - BottomSheetBehavior bottomSheetBehavior; - GestureDetector gestureDetector; private static final String PREF_NAME = "customDialogPreference"; - private static int sensorType = 0; - private static int highLimit = 1000; + private static int highLimit = 20; private static int updatePeriod = 100; - private BarometerActivity.SensorDataFetch sensorDataFetch; - + private final Object lock = new Object(); + BottomSheetBehavior bottomSheetBehavior; + GestureDetector gestureDetector; @BindView(R.id.barometer_max) TextView statMax; @BindView(R.id.barometer_min) @@ -68,23 +63,7 @@ public class BarometerActivity extends AppCompatActivity { @BindView(R.id.chart_barometer) LineChart mChart; @BindView(R.id.barometer) - TubeSpeedometer barometer; - - private BMP180 sensorBMP180 = null; - private SensorManager sensorManager; - private Sensor sensor; - private ScienceLab scienceLab; - private long startTime; - private int flag; - private ArrayList entries; - private float currentMin; - private float currentMax; - private YAxis y; - private volatile boolean monitor = true; - private Unbinder unbinder; - - private final Object lock = new Object(); - + PointerSpeedometer barometer; //bottomSheet @BindView(R.id.bottom_sheet) LinearLayout bottomSheet; @@ -102,6 +81,19 @@ public class BarometerActivity extends AppCompatActivity { ImageView bottomSheetSchematic; @BindView(R.id.custom_dialog_desc) TextView bottomSheetDesc; + private BarometerActivity.SensorDataFetch sensorDataFetch; + private BMP180 sensorBMP180 = null; + private SensorManager sensorManager; + private Sensor sensor; + private ScienceLab scienceLab; + private long startTime; + private int flag; + private ArrayList entries; + private float currentMin; + private float currentMax; + private YAxis y; + private volatile boolean monitor = true; + private Unbinder unbinder; public static BarometerActivity newInstance() { return new BarometerActivity(); @@ -113,16 +105,8 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_barometer_main); ButterKnife.bind(this); + setUpBottomSheet(); - tvShadow.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if(bottomSheetBehavior.getState()==BottomSheetBehavior.STATE_EXPANDED) - bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); - tvShadow.setVisibility(View.GONE); - } - }); - BarometerActivity.newInstance(); currentMin = 10000; entries = new ArrayList<>(); @@ -156,12 +140,7 @@ public void onClick(DialogInterface dialog, int which) { default: break; } - } - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.fragment_barometer, container, false); - unbinder = ButterKnife.bind(this, view); Runnable runnable = new Runnable() { @Override public void run() { @@ -218,7 +197,7 @@ public void run() { Thread dataThread = new Thread(runnable); dataThread.start(); - barometer.setMaxSpeed(10000); + barometer.setMaxSpeed(100); XAxis x = mChart.getXAxis(); this.y = mChart.getAxisLeft(); @@ -252,16 +231,86 @@ public void run() { y.setLabelCount(10); y2.setDrawGridLines(false); + } - return view; + @Override + protected void onDestroy() { + super.onDestroy(); + monitor = false; + if (sensor != null && sensorDataFetch != null) { + sensorManager.unregisterListener(sensorDataFetch); + sensorDataFetch.cancel(true); + } } - public static void setParameters(int sensorType, int highLimit, int updatePeriod) { - BarometerActivity.sensorType = sensorType; - BarometerActivity.highLimit = highLimit; - BarometerActivity.updatePeriod = updatePeriod; + private void setUpBottomSheet() { + bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet); + + final SharedPreferences settings = this.getSharedPreferences(PREF_NAME, MODE_PRIVATE); + Boolean isFirstTime = settings.getBoolean("BarometerFirstTime", true); + + bottomSheetGuideTitle.setText(R.string.barometer); + bottomSheetDesc.setText(R.string.barometer_intro); + bottomSheetSchematic.setImageResource(R.drawable.bmp180_schematic); + bottomSheetDesc.setText(R.string.barometer_desc); + + if (isFirstTime) { + bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); + tvShadow.setVisibility(View.VISIBLE); + tvShadow.setAlpha(0.8f); + arrowUpDown.setRotation(180); + bottomSheetSlideText.setText(R.string.hide_guide_text); + SharedPreferences.Editor editor = settings.edit(); + editor.putBoolean("BarometerFirstTime", false); + editor.apply(); + } else { + bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); + } + + bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() { + private Handler handler = new Handler(); + private Runnable runnable = new Runnable() { + @Override + public void run() { + bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); + } + }; + + @Override + public void onStateChanged(@NonNull final View bottomSheet, int newState) { + switch (newState) { + case BottomSheetBehavior.STATE_EXPANDED: + handler.removeCallbacks(runnable); + bottomSheetSlideText.setText(R.string.hide_guide_text); + break; + + case BottomSheetBehavior.STATE_COLLAPSED: + handler.postDelayed(runnable, 2000); + break; + + default: + handler.removeCallbacks(runnable); + bottomSheetSlideText.setText(R.string.show_guide_text); + break; + } + } + + @Override + public void onSlide(@NonNull View bottomSheet, float slideOffset) { + Float value = (float) MathUtils.map((double) slideOffset, 0.0, 1.0, 0.0, 0.8); + tvShadow.setVisibility(View.VISIBLE); + tvShadow.setAlpha(value); + arrowUpDown.setRotation(slideOffset * 180); + } + }); + gestureDetector = new GestureDetector(this, new SwipeGestureDetector(bottomSheetBehavior)); } + @Override + public boolean onTouchEvent(MotionEvent event) { + gestureDetector.onTouchEvent(event); + return super.onTouchEvent(event); + } private class SensorDataFetch extends AsyncTask implements SensorEventListener { @@ -299,6 +348,7 @@ protected void onPostExecute(Void aVoid) { @Override public void onSensorChanged(SensorEvent event) { data = Float.valueOf(df.format(event.values[0])); + data = data * 101325; // Convert hPa to atm unit visualizeData(); unRegisterListener(); } @@ -327,6 +377,8 @@ private void visualizeData() { count++; sum += item.getY(); } + statMax.setText(String.valueOf(currentMax)); + statMin.setText(String.valueOf(currentMin)); statMean.setText(Float.toString(Float.valueOf(df.format(sum / count)))); LineDataSet dataSet = new LineDataSet(entries, getString(R.string.barometer)); @@ -335,8 +387,6 @@ private void visualizeData() { mChart.setData(data); mChart.notifyDataSetChanged(); - mChart.setVisibleXRangeMaximum(10); - mChart.moveViewToX(data.getEntryCount()); mChart.invalidate(); } @@ -350,83 +400,4 @@ private void unRegisterListener() { sensorManager.unregisterListener(this); } } - - public void onDestroyView() { - super.onDestroy(); - monitor = false; - if (sensor != null && sensorDataFetch != null) { - sensorManager.unregisterListener(sensorDataFetch); - sensorDataFetch.cancel(true); - } - unbinder.unbind(); - } - - private void setUpBottomSheet() { - bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet); - - final SharedPreferences settings = this.getSharedPreferences(PREF_NAME, MODE_PRIVATE); - Boolean isFirstTime = settings.getBoolean("BarometerFirstTime", true); - - bottomSheetGuideTitle.setText(R.string.barometer); - bottomSheetDesc.setText(R.string.barometer_intro); - bottomSheetSchematic.setImageResource(R.drawable.bmp180_schematic); - bottomSheetDesc.setText(R.string.barometer_desc); - - if (isFirstTime) { - bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); - tvShadow.setVisibility(View.VISIBLE); - tvShadow.setAlpha(0.8f); - arrowUpDown.setRotation(180); - bottomSheetSlideText.setText(R.string.hide_guide_text); - SharedPreferences.Editor editor = settings.edit(); - editor.putBoolean("BarometerFirstTime", false); - editor.apply(); - } else { - bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); - } - - bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() { - private Handler handler = new Handler(); - private Runnable runnable = new Runnable() { - @Override - public void run() { - bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); - } - }; - - @Override - public void onStateChanged(@NonNull final View bottomSheet, int newState) { - switch (newState) { - case BottomSheetBehavior.STATE_EXPANDED: - handler.removeCallbacks(runnable); - bottomSheetSlideText.setText(R.string.hide_guide_text); - break; - - case BottomSheetBehavior.STATE_COLLAPSED: - handler.postDelayed(runnable, 2000); - break; - - default: - handler.removeCallbacks(runnable); - bottomSheetSlideText.setText(R.string.show_guide_text); - break; - } - } - - @Override - public void onSlide(@NonNull View bottomSheet, float slideOffset) { - Float value = (float) MathUtils.map((double) slideOffset, 0.0, 1.0, 0.0, 0.8); - tvShadow.setVisibility(View.VISIBLE); - tvShadow.setAlpha(value); - arrowUpDown.setRotation(slideOffset * 180); - } - }); - gestureDetector = new GestureDetector(this, new SwipeGestureDetector(bottomSheetBehavior)); - } - - @Override - public boolean onTouchEvent(MotionEvent event) { - gestureDetector.onTouchEvent(event); //Gesture detector need this to transfer touch event to the gesture detector. - return super.onTouchEvent(event); - } } diff --git a/app/src/main/java/io/pslab/fragment/BarometerFragment.java b/app/src/main/java/io/pslab/fragment/BarometerFragment.java deleted file mode 100644 index 83bba4b1f..000000000 --- a/app/src/main/java/io/pslab/fragment/BarometerFragment.java +++ /dev/null @@ -1,304 +0,0 @@ -package io.pslab.fragment; - -import android.annotation.SuppressLint; -import android.graphics.Color; -import android.hardware.Sensor; -import android.hardware.SensorEvent; -import android.hardware.SensorEventListener; -import android.hardware.SensorManager; -import android.os.AsyncTask; -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import com.github.anastr.speedviewlib.TubeSpeedometer; -import com.github.mikephil.charting.charts.LineChart; -import com.github.mikephil.charting.components.Legend; -import com.github.mikephil.charting.components.XAxis; -import com.github.mikephil.charting.components.YAxis; -import com.github.mikephil.charting.data.Entry; -import com.github.mikephil.charting.data.LineData; -import com.github.mikephil.charting.data.LineDataSet; - -import io.pslab.R; - -import java.io.IOException; -import java.text.DecimalFormat; - -import io.pslab.communication.ScienceLab; -import io.pslab.communication.sensors.BMP180; -import io.pslab.others.ScienceLabCommon; - -import java.util.ArrayList; -import java.util.Arrays; - -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.Unbinder; - -import static android.content.Context.SENSOR_SERVICE; - -public class BarometerFragment extends Fragment { - - private static int sensorType = 0; - private static int highLimit = 1000; - private static int updatePeriod = 100; - private SensorDataFetch sensorDataFetch; - - @BindView(R.id.barometer_max) - TextView statMax; - @BindView(R.id.barometer_min) - TextView statMin; - @BindView(R.id.barometer_mean) - TextView statMean; - @BindView(R.id.chart_barometer) - LineChart mChart; - @BindView(R.id.barometer) - TubeSpeedometer barometer; - - private BMP180 sensorBMP180 = null; - private SensorManager sensorManager; - private Sensor sensor; - private ScienceLab scienceLab; - private long startTime; - private int flag; - private ArrayList entries; - private float currentMin; - private float currentMax; - private YAxis y; - private volatile boolean monitor = true; - private Unbinder unbinder; - - private final Object lock = new Object(); - - public static BarometerFragment newInstance() { - return new BarometerFragment(); - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setRetainInstance(true); - currentMin = 10000; - entries = new ArrayList<>(); - switch (sensorType) { - case 0: - sensorManager = (SensorManager) getContext().getSystemService(SENSOR_SERVICE); - sensor = sensorManager != null ? sensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE) : null; - break; - case 1: - scienceLab = ScienceLabCommon.scienceLab; - break; - default: - break; - } - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.fragment_barometer, container, false); - unbinder = ButterKnife.bind(this, view); - Runnable runnable = new Runnable() { - @Override - public void run() { - if (flag == 0) { - startTime = System.currentTimeMillis(); - flag = 1; - switch (sensorType) { - case 0: - while (monitor) { - if (sensor != null) { - sensorDataFetch = new SensorDataFetch(); - sensorDataFetch.execute(); - synchronized (lock) { - try { - lock.wait(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - try { - Thread.sleep(updatePeriod); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - break; - case 1: - while (monitor) { - if (scienceLab.isConnected()) { - sensorDataFetch = new SensorDataFetch(); - sensorDataFetch.execute(); - synchronized (lock) { - try { - lock.wait(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - try { - Thread.sleep(updatePeriod); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - break; - default: - break; - } - } - } - }; - Thread dataThread = new Thread(runnable); - dataThread.start(); - - barometer.setMaxSpeed(10000); - - XAxis x = mChart.getXAxis(); - this.y = mChart.getAxisLeft(); - YAxis y2 = mChart.getAxisRight(); - - mChart.setTouchEnabled(true); - mChart.setHighlightPerDragEnabled(true); - mChart.setDragEnabled(true); - mChart.setScaleEnabled(true); - mChart.setDrawGridBackground(false); - mChart.setPinchZoom(true); - mChart.setScaleYEnabled(false); - mChart.setBackgroundColor(Color.BLACK); - mChart.getDescription().setEnabled(false); - - LineData data = new LineData(); - mChart.setData(data); - - Legend l = mChart.getLegend(); - l.setForm(Legend.LegendForm.LINE); - l.setTextColor(Color.WHITE); - - x.setTextColor(Color.WHITE); - x.setDrawGridLines(true); - x.setAvoidFirstLastClipping(true); - - y.setTextColor(Color.WHITE); - y.setAxisMaximum(currentMax); - y.setAxisMinimum(currentMin); - y.setDrawGridLines(true); - y.setLabelCount(10); - - y2.setDrawGridLines(false); - - return view; - } - - public static void setParameters(int sensorType, int highLimit, int updatePeriod) { - BarometerFragment.sensorType = sensorType; - BarometerFragment.highLimit = highLimit; - BarometerFragment.updatePeriod = updatePeriod; - } - - - private class SensorDataFetch extends AsyncTask implements SensorEventListener { - - private float data; - private long timeElapsed; - private int count = 0; - private float sum = 0; - private DecimalFormat df = new DecimalFormat("#.##"); - - @Override - protected Void doInBackground(Void... params) { - try { - if (sensorBMP180 != null) { - data = Float.valueOf(Arrays.toString(sensorBMP180.getRaw())); - sensorManager.unregisterListener(this); - } else if (sensor != null) { - sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL); - } - } catch (IOException e) { - e.printStackTrace(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - return null; - } - - protected void onPostExecute(Void aVoid) { - super.onPostExecute(aVoid); - visualizeData(); - synchronized (lock) { - lock.notify(); - } - } - - @Override - public void onSensorChanged(SensorEvent event) { - data = Float.valueOf(df.format(event.values[0])); - visualizeData(); - unRegisterListener(); - } - - @SuppressLint("SetTextI18n") - private void visualizeData() { - if (currentMax < data) { - currentMax = data; - statMax.setText(String.valueOf(data)); - } else if (currentMin > data) { - currentMin = data; - statMin.setText(String.valueOf(data)); - } - - y.setAxisMaximum(currentMax); - y.setAxisMinimum(currentMin); - y.setLabelCount(10); - barometer.setSpeedAt(data); - - if (data > highLimit) barometer.setIndicatorColor(Color.RED); - else barometer.setIndicatorColor(Color.WHITE); - timeElapsed = (System.currentTimeMillis() - startTime) / 1000; - entries.add(new Entry((float) timeElapsed, data)); - - for (Entry item : entries) { - count++; - sum += item.getY(); - } - statMean.setText(Float.toString(Float.valueOf(df.format(sum / count)))); - - LineDataSet dataSet = new LineDataSet(entries, getString(R.string.lux)); - LineData data = new LineData(dataSet); - dataSet.setDrawCircles(false); - - mChart.setData(data); - mChart.notifyDataSetChanged(); - mChart.setVisibleXRangeMaximum(10); - mChart.moveViewToX(data.getEntryCount()); - mChart.invalidate(); - } - - - @Override - public void onAccuracyChanged(Sensor sensor, int accuracy) { - //do nothing - } - - private void unRegisterListener() { - sensorManager.unregisterListener(this); - } - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - monitor = false; - if (sensor != null && sensorDataFetch != null) { - sensorManager.unregisterListener(sensorDataFetch); - sensorDataFetch.cancel(true); - } - unbinder.unbind(); - } -} diff --git a/app/src/main/res/layout/activity_barometer.xml b/app/src/main/res/layout/activity_barometer.xml index 19288fe2d..4475ee0b6 100644 --- a/app/src/main/res/layout/activity_barometer.xml +++ b/app/src/main/res/layout/activity_barometer.xml @@ -20,4 +20,266 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_barometer_main.xml b/app/src/main/res/layout/activity_barometer_main.xml index 64e673898..671c188ee 100644 --- a/app/src/main/res/layout/activity_barometer_main.xml +++ b/app/src/main/res/layout/activity_barometer_main.xml @@ -12,11 +12,6 @@ android:background="@color/black" android:alpha="0"/> - - - \ No newline at end of file + diff --git a/app/src/main/res/layout/fragment_barometer.xml b/app/src/main/res/layout/fragment_barometer.xml deleted file mode 100644 index a8384c5ca..000000000 --- a/app/src/main/res/layout/fragment_barometer.xml +++ /dev/null @@ -1,267 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From cb39a4f99a89ce5b9279b9d25f7739cb2fb58bf1 Mon Sep 17 00:00:00 2001 From: Princejhabak Date: Sun, 21 Oct 2018 12:32:30 +0530 Subject: [PATCH 4/7] feat: Add checkable behavior to menu items under other category in the navigation drawer (#1405) --- app/src/main/res/menu/activity_main_drawer.xml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/menu/activity_main_drawer.xml b/app/src/main/res/menu/activity_main_drawer.xml index 72f7e54bf..a32009ff2 100644 --- a/app/src/main/res/menu/activity_main_drawer.xml +++ b/app/src/main/res/menu/activity_main_drawer.xml @@ -24,11 +24,13 @@ + android:title="@string/nav_help_feedback" + android:checkable="true" /> + android:title="@string/nav_about_us" + android:checkable="true" /> Date: Sun, 21 Oct 2018 12:35:26 +0530 Subject: [PATCH 5/7] Changing different recording button logo to one in two activities (#1411) --- .../pslab/activity/AccelerometerActivity.java | 21 ++++++------- .../io/pslab/activity/MultimeterActivity.java | 30 ++++++++----------- app/src/main/res/menu/data_log_menu.xml | 2 +- app/src/main/res/menu/multimeter_log_menu.xml | 2 +- 4 files changed, 23 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/io/pslab/activity/AccelerometerActivity.java b/app/src/main/java/io/pslab/activity/AccelerometerActivity.java index 49021f5a3..d149103c1 100644 --- a/app/src/main/java/io/pslab/activity/AccelerometerActivity.java +++ b/app/src/main/java/io/pslab/activity/AccelerometerActivity.java @@ -53,18 +53,11 @@ public class AccelerometerActivity extends AppCompatActivity { public boolean recordData = false; public boolean locationPref; - private boolean checkGpsOnResume = false; - private boolean isRecordingStarted = false; - private boolean isDataRecorded = false; public GPSLogger gpsLogger; public CSVLogger accLogger; - - private Menu menu; AccelerometerAdapter adapter; - BottomSheetBehavior bottomSheetBehavior; GestureDetector gestureDetector; - @BindView(R.id.accel_toolbar) Toolbar mToolbar; @BindView(R.id.accel_coordinator_layout) @@ -85,6 +78,10 @@ public class AccelerometerActivity extends AppCompatActivity { ImageView bottomSheetSchematic; @BindView(R.id.custom_dialog_desc) TextView bottomSheetDesc; + private boolean checkGpsOnResume = false; + private boolean isRecordingStarted = false; + private boolean isDataRecorded = false; + private Menu menu; @Override protected void onCreate(Bundle savedInstanceState) { @@ -97,7 +94,7 @@ protected void onCreate(Bundle savedInstanceState) { tvShadow.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if(bottomSheetBehavior.getState()==BottomSheetBehavior.STATE_EXPANDED) + if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); tvShadow.setVisibility(View.GONE); } @@ -131,7 +128,7 @@ public boolean onOptionsItemSelected(MenuItem item) { return true; } if (recordData) { - item.setIcon(R.drawable.record_icon); + item.setIcon(R.drawable.ic_record_white); adapter.setRecordingStatus(false); recordData = false; CustomSnackBar.showSnackBar(coordinatorLayout, getString(R.string.data_recording_paused), null, null); @@ -163,7 +160,7 @@ public boolean onOptionsItemSelected(MenuItem item) { case R.id.record_csv_data: if (isDataRecorded) { MenuItem item1 = menu.findItem(R.id.record_pause_data); - item1.setIcon(R.drawable.record_icon); + item1.setIcon(R.drawable.ic_record_white); // Export Data ArrayList dataX = adapter.getEntries(0); @@ -214,7 +211,7 @@ public void onClick(DialogInterface dialogInterface, int i) { case R.id.delete_csv_data: if (isDataRecorded) { MenuItem item1 = menu.findItem(R.id.record_pause_data); - item1.setIcon(R.drawable.record_icon); + item1.setIcon(R.drawable.ic_record_white); adapter.setRecordingStatus(false); recordData = false; isRecordingStarted = false; @@ -247,7 +244,7 @@ public void onClick(DialogInterface dialogInterface, int i) { @Override protected void onDestroy() { super.onDestroy(); - if(isRecordingStarted) { + if (isRecordingStarted) { accLogger.deleteFile(); isRecordingStarted = false; } diff --git a/app/src/main/java/io/pslab/activity/MultimeterActivity.java b/app/src/main/java/io/pslab/activity/MultimeterActivity.java index c4723d1c8..58d91d7be 100644 --- a/app/src/main/java/io/pslab/activity/MultimeterActivity.java +++ b/app/src/main/java/io/pslab/activity/MultimeterActivity.java @@ -58,8 +58,11 @@ public class MultimeterActivity extends AppCompatActivity { - private ScienceLab scienceLab; - + public static final String PREFS_NAME = "customDialogPreference"; + public static final String NAME = "savingData"; + private static final int MY_PERMISSIONS_REQUEST_STORAGE_FOR_DATA = 101; + public boolean recordData = false; + public CSVLogger multimeterLogger; @BindView(R.id.multimeter_toolbar) Toolbar mToolbar; @BindView(R.id.quantity) @@ -74,7 +77,6 @@ public class MultimeterActivity extends AppCompatActivity { Button read; @BindView(R.id.selector) SwitchCompat aSwitch; - @BindView(R.id.multimeter_coordinator_layout) CoordinatorLayout coordinatorLayout; //bottomSheet @@ -94,27 +96,19 @@ public class MultimeterActivity extends AppCompatActivity { ImageView bottomSheetSchematic; @BindView(R.id.custom_dialog_desc) TextView bottomSheetDesc; - - public boolean recordData = false; - + BottomSheetBehavior bottomSheetBehavior; + GestureDetector gestureDetector; + SharedPreferences multimeter_data; + private ScienceLab scienceLab; private int knobState; private String dataRecorded; private String valueRecorded; private Menu menu; private Boolean switchIsChecked; private String[] knobMarker; - public CSVLogger multimeterLogger; private boolean isRecordingStarted = false; private boolean isDataRecorded = false; - BottomSheetBehavior bottomSheetBehavior; - GestureDetector gestureDetector; - public static final String PREFS_NAME = "customDialogPreference"; - private static final int MY_PERMISSIONS_REQUEST_STORAGE_FOR_DATA = 101; - - public static final String NAME = "savingData"; - SharedPreferences multimeter_data; - @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -412,7 +406,7 @@ public boolean onOptionsItemSelected(MenuItem item) { return true; } if (recordData) { - item.setIcon(R.drawable.record_icon); + item.setIcon(R.drawable.ic_record_white); recordData = false; CustomSnackBar.showSnackBar(coordinatorLayout, getString(R.string.data_recording_paused), null, null); } else { @@ -429,7 +423,7 @@ public boolean onOptionsItemSelected(MenuItem item) { case R.id.record_csv_data: if (isDataRecorded) { MenuItem item1 = menu.findItem(R.id.record_pause_data); - item1.setIcon(R.drawable.record_icon); + item1.setIcon(R.drawable.ic_record_white); multimeterLogger.writeCSVFile(dataRecorded + "\n" + valueRecorded + "\n"); dataRecorded = "Data"; valueRecorded = "Value"; @@ -462,7 +456,7 @@ public void onClick(DialogInterface dialogInterface, int i) { case R.id.delete_csv_data: if (isDataRecorded) { MenuItem item1 = menu.findItem(R.id.record_pause_data); - item1.setIcon(R.drawable.record_icon); + item1.setIcon(R.drawable.ic_record_white); recordData = false; isRecordingStarted = false; isDataRecorded = false; diff --git a/app/src/main/res/menu/data_log_menu.xml b/app/src/main/res/menu/data_log_menu.xml index f2e9a6bfb..e48763890 100644 --- a/app/src/main/res/menu/data_log_menu.xml +++ b/app/src/main/res/menu/data_log_menu.xml @@ -3,7 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto"> Date: Sun, 21 Oct 2018 12:36:17 +0530 Subject: [PATCH 6/7] added auto hide top bar (#1413) --- .../activity/LogicalAnalyzerActivity.java | 20 +++++++++++++++++++ .../pslab/activity/OscilloscopeActivity.java | 18 +++++++++++++++++ .../pslab/activity/WaveGeneratorActivity.java | 19 ++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/app/src/main/java/io/pslab/activity/LogicalAnalyzerActivity.java b/app/src/main/java/io/pslab/activity/LogicalAnalyzerActivity.java index 4f562156a..84761fe05 100644 --- a/app/src/main/java/io/pslab/activity/LogicalAnalyzerActivity.java +++ b/app/src/main/java/io/pslab/activity/LogicalAnalyzerActivity.java @@ -1,10 +1,13 @@ package io.pslab.activity; +import android.os.Build; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.MenuItem; +import android.view.View; +import android.view.WindowManager; import io.pslab.R; import io.pslab.communication.ScienceLab; @@ -31,6 +34,23 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { setContentView(R.layout.activity_logic_analyzer); scienceLab = ScienceLabCommon.scienceLab; ButterKnife.bind(this); + + if (Build.VERSION.SDK_INT < 16) { + getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, + WindowManager.LayoutParams.FLAG_FULLSCREEN); + } + else { + View decorView = getWindow().getDecorView(); + + decorView.setSystemUiVisibility((View.SYSTEM_UI_FLAG_LAYOUT_STABLE + | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + | View.SYSTEM_UI_FLAG_FULLSCREEN + | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_FULLSCREEN + | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)); + } + getSupportFragmentManager().beginTransaction().add(R.id.la_frame_layout, LALogicLinesFragment.newInstance(this)).commit(); setSupportActionBar(toolbar); if (getSupportActionBar() != null) { diff --git a/app/src/main/java/io/pslab/activity/OscilloscopeActivity.java b/app/src/main/java/io/pslab/activity/OscilloscopeActivity.java index d72a7b6da..c38443ab1 100644 --- a/app/src/main/java/io/pslab/activity/OscilloscopeActivity.java +++ b/app/src/main/java/io/pslab/activity/OscilloscopeActivity.java @@ -6,6 +6,7 @@ import android.graphics.Color; import android.graphics.Point; import android.os.AsyncTask; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.support.annotation.IdRes; @@ -19,6 +20,7 @@ import android.view.GestureDetector; import android.view.MotionEvent; import android.view.View; +import android.view.WindowManager; import android.widget.FrameLayout; import android.widget.ImageButton; import android.widget.ImageView; @@ -185,6 +187,22 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { setContentView(R.layout.activity_oscilloscope); ButterKnife.bind(this); + if (Build.VERSION.SDK_INT < 16) { + getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, + WindowManager.LayoutParams.FLAG_FULLSCREEN); + } + else { + View decorView = getWindow().getDecorView(); + + decorView.setSystemUiVisibility((View.SYSTEM_UI_FLAG_LAYOUT_STABLE + | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + | View.SYSTEM_UI_FLAG_FULLSCREEN + | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_FULLSCREEN + | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)); + } + setUpBottomSheet(); parentLayout.setOnClickListener(new View.OnClickListener() { @Override diff --git a/app/src/main/java/io/pslab/activity/WaveGeneratorActivity.java b/app/src/main/java/io/pslab/activity/WaveGeneratorActivity.java index 4bc0bc5c7..66f56fa21 100644 --- a/app/src/main/java/io/pslab/activity/WaveGeneratorActivity.java +++ b/app/src/main/java/io/pslab/activity/WaveGeneratorActivity.java @@ -5,6 +5,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.graphics.drawable.Drawable; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.support.annotation.NonNull; @@ -18,6 +19,7 @@ import android.view.MotionEvent; import android.view.View; import android.view.Window; +import android.view.WindowManager; import android.widget.Button; import android.widget.ImageButton; import android.widget.ImageView; @@ -181,6 +183,23 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_wave_generator_main); ButterKnife.bind(this); + + if (Build.VERSION.SDK_INT < 16) { + getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, + WindowManager.LayoutParams.FLAG_FULLSCREEN); + } + else { + View decorView = getWindow().getDecorView(); + + decorView.setSystemUiVisibility((View.SYSTEM_UI_FLAG_LAYOUT_STABLE + | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + | View.SYSTEM_UI_FLAG_FULLSCREEN + | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_FULLSCREEN + | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)); + } + scienceLab = ScienceLabCommon.scienceLab; if (!WaveGeneratorCommon.isInitialized) { new WaveGeneratorCommon(true); From 15c633b4124371246b22196bb1706c193d5eaaaa Mon Sep 17 00:00:00 2001 From: Padmal Date: Wed, 24 Oct 2018 09:20:05 +0700 Subject: [PATCH 7/7] chore: upgrade app to v2.0.5 (#1424) --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 0fad79f72..21c72daa3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,8 +8,8 @@ android { applicationId "io.pslab" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 5 - versionName "2.0.4" + versionCode 6 + versionName "2.0.5" multiDexEnabled true testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" }