diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index 3ee1ee1b5..ea591cf0c 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -1,6 +1,5 @@ name-template: 'PSLab Version $NEXT_PATCH_VERSION' tag-template: 'v$NEXT_PATCH_VERSION' -change-template: '- $TITLE (#$NUMBER) - @$AUTHOR' categories: - title: ':rocket: Features and Enhancements' labels: @@ -12,6 +11,7 @@ categories: label: 'Chore' - title: ':page_facing_up: Documentation' label: 'Documentation' +change-template: '- $TITLE (#$NUMBER) - @$AUTHOR' template: |- ## Changes $CHANGES diff --git a/README.md b/README.md index 9980c9310..d65e94b18 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,30 @@ # PSLab Android App -Get it on Google Play -Get it on F-Droid +Repository for the PSLab Android App for performing experiments with the [Pocket Science Lab](https://pslab.io) open-hardware platform. [![Build Status](https://travis-ci.org/fossasia/pslab-android.svg?branch=development)](https://travis-ci.org/fossasia/pslab-android) -[![Gitter](https://badges.gitter.im/fossasia/pslab.svg)](https://gitter.im/fossasia/pslab?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/dd728d91bb5743ff916c16c1251f8dd5)](https://www.codacy.com/app/praveenkumar103/pslab-android?utm_source=github.com&utm_medium=referral&utm_content=fossasia/pslab-android&utm_campaign=Badge_Grade) [![Mailing List](https://img.shields.io/badge/Mailing%20List-FOSSASIA-blue.svg)](https://groups.google.com/forum/#!forum/pslab-fossasia) -[![Twitter Follow](https://img.shields.io/twitter/follow/pslabio.svg?style=social&label=Follow&maxAge=2592000?style=flat-square)](https://twitter.com/pslabio) - ![Minimum API Level](https://img.shields.io/badge/Min%20API%20Level-23-green) ![Maximum API Level](https://img.shields.io/badge/Max%20API%20Level-28-orange) ![GitHub repo size](https://img.shields.io/github/repo-size/fossasia/pslab-android) +[![Gitter](https://badges.gitter.im/fossasia/pslab.svg)](https://gitter.im/fossasia/pslab?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) +[![Twitter Follow](https://img.shields.io/twitter/follow/pslabio.svg?style=social&label=Follow&maxAge=2592000?style=flat-square)](https://twitter.com/pslabio) This repository holds the Android App for performing experiments with [PSLab](https://pslab.io/). PSLab is a tiny pocket science lab that provides an array of equipment for doing science and engineering experiments. It can function like an oscilloscope, waveform generator, frequency counter, programmable voltage and current source and also as a data logger. Our website is at https://pslab.io +Get it on Google Play +Get it on F-Droid + +## Buy + +* You can get a Pocket Science Lab device from the [FOSSASIA Shop](https://fossasia.com). +* More resellers are listed on the [PSLab website](https://pslab.io/shop/). + ## Communication -Please join us on the following channels: -* [Pocket Science Channel](https://gitter.im/fossasia/pslab) -* [Mailing List](https://groups.google.com/forum/#!forum/pslab-fossasia) +* The PSLab [chat channel is on Gitter](https://gitter.im/fossasia/pslab). +* Please also join us on the [PSLab Mailing List](https://groups.google.com/forum/#!forum/pslab-fossasia). ## Roadmap - [x] First we need to get communication between Android App and PSLab working. @@ -31,9 +36,9 @@ Please join us on the following channels: - +
@@ -44,29 +49,24 @@ Please join us on the following channels:
- - + +
- - + +
- -
- - - - +
@@ -74,6 +74,7 @@ Please join us on the following channels: +
@@ -86,8 +87,8 @@ Please join us on the following channels:
- - + +
@@ -107,10 +108,10 @@ Please join us on the following channels: | Logical Analyzer | Captures and displays signals from digital system | :heavy_check_mark: | | Wave Generator | Generates arbitrary analog and digital waveforms | :heavy_check_mark: | | Power Source | Generates programmable voltage and currents | :heavy_check_mark: | -| Lux Meter | Measures the ambient light intensity | :heavy_check_mark: | -| Baro Meter | Measures the Pressure | :heavy_check_mark: | -| AcceleroMeter | Measures the acceleration of the device | :heavy_check_mark: | -| Gyro Meter | Measures the rate of rotation | :heavy_check_mark: | +| Luxmeter | Measures the ambient light intensity | :heavy_check_mark: | +| Barometer | Measures the Pressure | :heavy_check_mark: | +| Accelerometer | Measures the acceleration of the device | :heavy_check_mark: | +| Gyrometer | Measures the rate of rotation | :heavy_check_mark: | | Compass | Measures the absolute rotation relative to earth magnetic poles | :heavy_check_mark: | | Thermometer | Measures the ambient temperature | :heavy_check_mark: | | Gas Sensor | Detects gases, including NH3, NOx, alcohol, benzene, smoke and CO2| :heavy_check_mark: | @@ -249,7 +250,7 @@ The project is maintained by - Lorenz Gerber ([@lorenzgerber](https://github.com/lorenzgerber)) - Wei Tat ([@cweitat](https://github.com/cweitat)) - Wai Gie ([@woshikie](https://github.com/woshikie)) - +- Neel Trivedi ([@neel1998](https://github.com/neel1998)) ## Alumni - Praveen Patil ([@wavicles](https://github.com/wavicles)) - Jithin ([@jithinbp](https://github.com/jithinbp)) diff --git a/app/build.gradle b/app/build.gradle index a23481f1b..4b09aefbe 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,8 +13,8 @@ android { applicationId "io.pslab" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 19 - versionName "2.0.18" + versionCode 20 + versionName "2.0.19" multiDexEnabled true testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } @@ -63,9 +63,11 @@ android { flavorDimensions 'default' productFlavors { fdroid { + resValue "string", "flavor", "Fdroid version" dimension = 'default' } playstore { + resValue "string", "flavor", "Play Store version" dimension = 'default' } } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0a6a4a3c2..00321a931 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -84,7 +84,7 @@ android:screenOrientation="portrait" /> + android:screenOrientation="portrait" /> diff --git a/app/src/main/java/io/pslab/activity/CreateConfigActivity.java b/app/src/main/java/io/pslab/activity/CreateConfigActivity.java index a9feceb5d..5e2ec1d37 100644 --- a/app/src/main/java/io/pslab/activity/CreateConfigActivity.java +++ b/app/src/main/java/io/pslab/activity/CreateConfigActivity.java @@ -5,14 +5,15 @@ import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; -import android.util.SparseBooleanArray; +import android.view.Gravity; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; +import android.widget.CheckBox; import android.widget.EditText; -import android.widget.ListView; +import android.widget.LinearLayout; import android.widget.Spinner; import android.widget.Toast; @@ -30,12 +31,12 @@ public class CreateConfigActivity extends AppCompatActivity { private ArrayList instrumentsList; private ArrayList instrumentParamsList; private ArrayList instrumentParamsListTitles; - private ListView paramsListView; private int selectedItem = 0; private String intervalUnit = "sec"; private EditText intervalEditText; private String interval; private View rootView; + private LinearLayout paramsListContainer; @Override protected void onCreate(Bundle savedInstanceState) { @@ -43,7 +44,7 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_create_config); Toolbar toolbar = findViewById(R.id.toolbar); rootView = findViewById(R.id.create_config_root_view); - paramsListView = findViewById(R.id.params_list); + paramsListContainer = findViewById(R.id.params_list_container); Spinner selectInstrumentSpinner = findViewById(R.id.select_instrument_spinner); Spinner intervalUnitSpinner = findViewById(R.id.interval_unit_spinner); intervalEditText = findViewById(R.id.interval_edit_text); @@ -95,10 +96,10 @@ public void onClick(View v) { if (interval.length() == 0) { Toast.makeText(CreateConfigActivity.this, getResources().getString(R.string.no_interval_message), Toast.LENGTH_SHORT).show(); } else { - SparseBooleanArray selectedParams = paramsListView.getCheckedItemPositions(); ArrayList selectedParamsList = new ArrayList<>(); - for (int i = 0; i < paramsListView.getCount(); i++) { - if (selectedParams.get(i)) { + for (int i = 0; i < paramsListContainer.getChildCount(); i ++) { + CheckBox checkBox = (CheckBox) paramsListContainer.getChildAt(i); + if (checkBox.isChecked()) { selectedParamsList.add(instrumentParamsList.get(selectedItem)[i]); } } @@ -133,8 +134,17 @@ private void createArrayLists() { } private void createCheckboxList() { - paramsListView.setAdapter(new ArrayAdapter(CreateConfigActivity.this, android.R.layout.simple_list_item_multiple_choice, instrumentParamsListTitles.get(selectedItem))); - paramsListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); + paramsListContainer.removeAllViews(); + String[] params = instrumentParamsListTitles.get(selectedItem); + for (int i = 0; i < params.length; i++){ + CheckBox checkBox = new CheckBox(CreateConfigActivity.this); + checkBox.setText(params[i]); + LinearLayout.LayoutParams checkBoxParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT); + checkBoxParams.gravity = Gravity.CENTER_HORIZONTAL; + checkBoxParams.setMargins(0,(int)getResources().getDimension(R.dimen.create_config_margin1),0,0); + checkBox.setLayoutParams(checkBoxParams); + paramsListContainer.addView(checkBox, i); + } } @Override diff --git a/app/src/main/java/io/pslab/activity/LogicalAnalyzerActivity.java b/app/src/main/java/io/pslab/activity/LogicalAnalyzerActivity.java index 31efdc317..bf9cac2c7 100644 --- a/app/src/main/java/io/pslab/activity/LogicalAnalyzerActivity.java +++ b/app/src/main/java/io/pslab/activity/LogicalAnalyzerActivity.java @@ -1,5 +1,6 @@ package io.pslab.activity; +import android.content.Intent; import android.content.SharedPreferences; import android.os.Build; import android.os.Bundle; @@ -10,6 +11,7 @@ import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.GestureDetector; +import android.view.Menu; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; @@ -20,15 +22,11 @@ import android.widget.TextView; import io.pslab.R; -import io.pslab.communication.ScienceLab; import io.pslab.fragment.LALogicLinesFragment; import io.pslab.models.LogicAnalyzerData; import io.pslab.others.LocalDataLog; import io.pslab.others.MathUtils; -import io.pslab.others.ScienceLabCommon; -import butterknife.BindView; -import butterknife.ButterKnife; import io.pslab.others.SwipeGestureDetector; import io.realm.RealmResults; @@ -40,9 +38,6 @@ public class LogicalAnalyzerActivity extends AppCompatActivity { public static final String PREFS_NAME = "LogicAnalyzerPreference"; - @BindView(R.id.logical_analyzer_toolbar) - Toolbar toolbar; - private ScienceLab scienceLab; private boolean isRunning = false; //Bottom Sheet @@ -56,13 +51,11 @@ public class LogicalAnalyzerActivity extends AppCompatActivity { private TextView bottomSheetDesc; private BottomSheetBehavior bottomSheetBehavior; private GestureDetector gestureDetector; - private TextView showText; - private boolean btnLongpressed; private final String KEY_LOG = "has_log"; private final String DATA_BLOCK = "data_block"; public boolean isPlayback = false; public RealmResults recordedLAData; - + private LALogicLinesFragment laLogicLinesFragment; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -70,8 +63,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_logic_analyzer); - scienceLab = ScienceLabCommon.scienceLab; - ButterKnife.bind(this); // Bottom Sheet guide bottomSheet = findViewById(R.id.bottom_sheet); @@ -82,7 +73,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { bottomSheetText = findViewById(R.id.custom_dialog_text); bottomSheetSchematic = findViewById(R.id.custom_dialog_schematic); bottomSheetDesc = findViewById(R.id.custom_dialog_desc); - showText = findViewById(R.id.show_guide_logic_analyzer); // Inflating bottom sheet dialog on how to use Logic Analyzer setUpBottomSheet(); tvShadow.setOnClickListener(new View.OnClickListener() { @@ -96,42 +86,16 @@ public void onClick(View v) { removeStatusBar(); - getSupportFragmentManager().beginTransaction().add(R.id.la_frame_layout, LALogicLinesFragment.newInstance(this)).commit(); + laLogicLinesFragment = LALogicLinesFragment.newInstance(this); + getSupportFragmentManager().beginTransaction().add(R.id.la_frame_layout, laLogicLinesFragment).commit(); + Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); + getSupportActionBar().setTitle(R.string.logical_analyzer); if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowHomeEnabled(true); } - ImageView guideImageView = findViewById(R.id.logic_analyzer_guide_button); - guideImageView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - bottomSheetBehavior.setState(bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN ? - BottomSheetBehavior.STATE_EXPANDED : BottomSheetBehavior.STATE_HIDDEN); - } - }); - guideImageView.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - showText.setVisibility(View.VISIBLE); - btnLongpressed = true; - return true; - } - }); - guideImageView.setOnTouchListener(new View.OnTouchListener() { - @Override - public boolean onTouch(View v, MotionEvent event) { - v.onTouchEvent(event); - if(event.getAction()==MotionEvent.ACTION_UP){ - if(btnLongpressed){ - showText.setVisibility(View.GONE); - btnLongpressed = false; - } - } - return true; - } - }); - if (getIntent().getExtras() != null && getIntent().getExtras().getBoolean(KEY_LOG)) { recordedLAData = LocalDataLog.with() .getBlockOfLARecords(getIntent().getExtras().getLong(DATA_BLOCK)); @@ -161,16 +125,35 @@ private void removeStatusBar() { | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)); } } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.logical_analyzer_menu, menu); + return true; + } + @Override public boolean onOptionsItemSelected(MenuItem item) { - int id = item.getItemId(); - if (id == android.R.id.home) { - onBackPressed(); - return true; + switch (item.getItemId()) { + case android.R.id.home: + finish(); + break; + case R.id.show_logged_data: + Intent intent = new Intent(LogicalAnalyzerActivity.this, DataLoggerActivity.class); + intent.putExtra(DataLoggerActivity.CALLER_ACTIVITY, getResources().getString(R.string.logical_analyzer)); + startActivity(intent); + break; + case R.id.save_graph: + laLogicLinesFragment.logData(); + break; + case R.id.show_guide: + bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); + break; + default: + break; } - return super.onOptionsItemSelected(item); + return true; } - @Override public void onBackPressed() { if (!isRunning) diff --git a/app/src/main/java/io/pslab/activity/MainActivity.java b/app/src/main/java/io/pslab/activity/MainActivity.java index ba056b789..8cfe81090 100644 --- a/app/src/main/java/io/pslab/activity/MainActivity.java +++ b/app/src/main/java/io/pslab/activity/MainActivity.java @@ -1,11 +1,9 @@ package io.pslab.activity; -import android.app.AlertDialog; import android.app.PendingIntent; import android.app.ProgressDialog; import android.content.BroadcastReceiver; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.hardware.usb.UsbDevice; @@ -24,7 +22,6 @@ import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.util.Log; -import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@ -41,8 +38,6 @@ import io.pslab.R; import io.pslab.communication.CommunicationHandler; import io.pslab.fragment.AboutUsFragment; -import io.pslab.fragment.BluetoothScanFragment; -import io.pslab.fragment.ESPFragment; import io.pslab.fragment.FAQFragment; import io.pslab.fragment.HomeFragment; import io.pslab.fragment.InstrumentsFragment; @@ -187,13 +182,11 @@ public void run() { private Fragment getHomeFragment() throws IOException { switch (navItemIndex) { - case 1: - return HomeFragment.newInstance(ScienceLabCommon.scienceLab.isConnected(), ScienceLabCommon.scienceLab.isDeviceFound()); case 2: - return null; - case 3: + return HomeFragment.newInstance(ScienceLabCommon.scienceLab.isConnected(), ScienceLabCommon.scienceLab.isDeviceFound()); + case 5: return AboutUsFragment.newInstance(); - case 4: + case 7: return FAQFragment.newInstance(); default: return InstrumentsFragment.newInstance(); @@ -228,11 +221,11 @@ private void selectNavMenu() { case 2: navigationView.getMenu().getItem(navItemIndex).setChecked(true); break; - case 3: - navigationView.getMenu().getItem(size_menu-1).getSubMenu().getItem(1).setChecked(true); + case 5: + navigationView.getMenu().getItem(navItemIndex).setChecked(true); break; - case 4: - navigationView.getMenu().getItem(size_menu-1).getSubMenu().getItem(0).setChecked(true); + case 7: + navigationView.getMenu().getItem(navItemIndex).setChecked(true); break; default: navigationView.getMenu().getItem(0).setChecked(true); @@ -250,7 +243,7 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) { CURRENT_TAG = TAG_INSTRUMENTS; break; case R.id.nav_device: - navItemIndex = 1; + navItemIndex = 2; CURRENT_TAG = TAG_DEVICE; break; case R.id.nav_settings: @@ -262,22 +255,19 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) { startActivity(intent); return true; case R.id.nav_about_us: - navItemIndex = 3; + navItemIndex = 5; CURRENT_TAG = TAG_ABOUTUS; break; case R.id.nav_help_feedback: - navItemIndex = 4; + navItemIndex = 7; CURRENT_TAG = TAG_FAQ; break; - case R.id.nav_report_us: - customTabService.launchUrl("https://goo.gl/forms/sHlmRAPFmzcGQ27u2"); + case R.id.nav_buy_pslab: + customTabService.launchUrl("https://pslab.io/shop/"); if (drawer != null) { drawer.closeDrawers(); } break; - case R.id.nav_app_version: - setTitleColor(R.color.gray); - break; case R.id.sensor_data_logger: if (drawer != null) { drawer.closeDrawers(); @@ -407,53 +397,9 @@ private void attemptToConnectPSLab() { } else { initialisationDialog.dismiss(); Toast.makeText(this, getString(R.string.device_not_found), Toast.LENGTH_SHORT).show(); - AlertDialog dialog = new AlertDialog.Builder(MainActivity.this) - .setMessage(getResources().getString(R.string.bluetooth_wifi_scan_dialog)) - .setPositiveButton(getResources().getString(R.string.bluetooth_scan_text), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(MainActivity.this); - LayoutInflater inflater = MainActivity.this.getLayoutInflater(); - View dialogView = inflater.inflate(R.layout.bluetooth_wifi_dialog_layout, null); - dialogBuilder.setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - dialog.cancel(); - } - }); - - dialogView.findViewById(R.id.bluetooth_btn).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - BluetoothScanFragment bluetoothScanFragment = new BluetoothScanFragment(); - bluetoothScanFragment.show(getSupportFragmentManager(), "bluetooth"); - bluetoothScanFragment.setCancelable(true); - dialog.cancel(); - } - }); - - dialogView.findViewById(R.id.wifi_btn).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - ESPFragment espFragment = new ESPFragment(); - espFragment.show(getSupportFragmentManager(), "wifi"); - espFragment.setCancelable(true); - dialog.cancel(); - } - }); - - dialogBuilder.setView(dialogView) - .create() - .show(); - } - }) - .setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.cancel(); - } - }).create(); - dialog.show(); + navItemIndex = 2; + CURRENT_TAG = TAG_DEVICE; + loadHomeFragment(); } } } diff --git a/app/src/main/java/io/pslab/activity/MultimeterActivity.java b/app/src/main/java/io/pslab/activity/MultimeterActivity.java index a5250af27..b27408a67 100644 --- a/app/src/main/java/io/pslab/activity/MultimeterActivity.java +++ b/app/src/main/java/io/pslab/activity/MultimeterActivity.java @@ -470,7 +470,6 @@ public boolean onPrepareOptionsMenu(Menu menu) { stopMenu = menu.findItem(R.id.stop_data); playMenu.setVisible(isPlayingBack); menu.findItem(R.id.record_pause_data).setVisible(!isPlayingBack); - menu.findItem(R.id.delete_csv_data).setVisible(!isPlayingBack); return super.onPrepareOptionsMenu(menu); } @@ -526,18 +525,6 @@ public void onClick(View view) { CustomSnackBar.showSnackBar(coordinatorLayout, getString(R.string.device_not_found), null, null, Snackbar.LENGTH_SHORT); } break; - case R.id.delete_csv_data: - if (isDataRecorded) { - MenuItem item1 = menu.findItem(R.id.record_pause_data); - item1.setIcon(R.drawable.ic_record_white); - recordData = false; - isRecordingStarted = false; - isDataRecorded = false; - multimeterLogger.deleteFile(); - CustomSnackBar.showSnackBar(coordinatorLayout, getString(R.string.data_deleted), null, null, Snackbar.LENGTH_SHORT); - } else - CustomSnackBar.showSnackBar(coordinatorLayout, getString(R.string.nothing_to_delete), null, null, Snackbar.LENGTH_SHORT); - break; case R.id.settings: Intent settingIntent = new Intent(this, SettingsActivity.class); settingIntent.putExtra("title", getResources().getString(R.string.multimeter_configurations)); diff --git a/app/src/main/java/io/pslab/activity/OscilloscopeActivity.java b/app/src/main/java/io/pslab/activity/OscilloscopeActivity.java index 87e831f7d..cc2b42066 100644 --- a/app/src/main/java/io/pslab/activity/OscilloscopeActivity.java +++ b/app/src/main/java/io/pslab/activity/OscilloscopeActivity.java @@ -20,8 +20,11 @@ import android.support.design.widget.Snackbar; import android.support.v4.app.Fragment; import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; import android.view.Display; import android.view.GestureDetector; +import android.view.Menu; +import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.Window; @@ -161,8 +164,6 @@ public class OscilloscopeActivity extends AppCompatActivity implements View.OnCl private Fragment dataAnalysisFragment; private Fragment xyPlotFragment; private Fragment playbackFragment; - @BindView(R.id.imageView_led_os) - ImageView ledImageView; @BindView(R.id.show_guide_oscilloscope) TextView showText; private ScienceLab scienceLab; @@ -179,9 +180,7 @@ public class OscilloscopeActivity extends AppCompatActivity implements View.OnCl private volatile boolean monitor = true; private BottomSheetBehavior bottomSheetBehavior; private GestureDetector gestureDetector; - private boolean btnLongpressed; private double maxAmp, maxFreq; - private ImageView recordButton; private boolean isRecording = false; private Realm realm; public RealmResults recordedOscilloscopeData; @@ -205,6 +204,9 @@ public class OscilloscopeActivity extends AppCompatActivity implements View.OnCl private String[] loggingYdata = new String[4]; public String xyPlotAxis1 = "CH1"; public String xyPlotAxis2 = "CH2"; + private boolean isPlayingback = false; + private boolean isPlaying = false; + private MenuItem playMenu; private enum CHANNEL {CH1, CH2, CH3, MIC} @@ -229,6 +231,14 @@ public void onClick(View v) { }); mainLayout = findViewById(R.id.oscilloscope_mail_layout); + Toolbar toolbar = findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + getSupportActionBar().setTitle(R.string.oscilloscope); + if (getSupportActionBar() != null) { + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowHomeEnabled(true); + } + channelIndexMap = new HashMap<>(); channelIndexMap.put(CHANNEL.CH1.toString(), 1); channelIndexMap.put(CHANNEL.CH2.toString(), 2); @@ -240,8 +250,6 @@ public void onClick(View v) { (LocationManager) getSystemService(Context.LOCATION_SERVICE)); csvLogger = new CSVLogger(getString(R.string.oscilloscope)); - recordButton = findViewById(R.id.oscilloscope_record_button); - scienceLab = ScienceLabCommon.scienceLab; x1 = mChart.getXAxis(); y1 = mChart.getAxisLeft(); @@ -447,18 +455,6 @@ public void run() { } } - if (!isInBuiltMicSelected && (!scienceLab.isConnected() || (!isCH1Selected && !isCH2Selected && !isCH3Selected && !isAudioInputSelected))) { - if (!String.valueOf(ledImageView.getTag()).equals("red")) { - runOnUiThread(new Runnable() { - @Override - public void run() { - ledImageView.setImageResource(R.drawable.red_led); - ledImageView.setTag("red"); - } - }); - } - } - if (scienceLab.isConnected() && isXYPlotSelected) { xyPlotTask = new XYPlotTask(); xyPlotTask.execute(xyPlotAxis1, xyPlotAxis2); @@ -481,42 +477,38 @@ public void run() { monitorThread = new Thread(runnable); monitorThread.start(); - ImageView guideImageView = findViewById(R.id.oscilloscope_guide_button); - guideImageView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - bottomSheetBehavior.setState(bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN ? - BottomSheetBehavior.STATE_EXPANDED : BottomSheetBehavior.STATE_HIDDEN); - } - }); - guideImageView.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - showText.setVisibility(View.VISIBLE); - btnLongpressed = true; - return true; - } - }); - guideImageView.setOnTouchListener(new View.OnTouchListener() { - @Override - public boolean onTouch(View v, MotionEvent event) { - v.onTouchEvent(event); - if (event.getAction() == MotionEvent.ACTION_UP) { - if (btnLongpressed) { - showText.setVisibility(View.GONE); - btnLongpressed = false; - } - } - return true; - } - }); + if (getIntent().getExtras() != null && getIntent().getExtras().getBoolean(KEY_LOG)) { + recordedOscilloscopeData = LocalDataLog.with() + .getBlockOfOscilloscopeRecords(getIntent().getExtras().getLong(DATA_BLOCK)); + isPlayingback = true; + setLayoutForPlayback(); + } + } - recordButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.activity_landscape_menu, menu); + return true; + } + + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + playMenu = menu.findItem(R.id.play_data); + menu.findItem(R.id.record_pause_data).setVisible(!isPlayingback); + menu.findItem(R.id.play_data).setVisible(isPlayingback); + return super.onPrepareOptionsMenu(menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + finish(); + break; + case R.id.record_pause_data: if (isRecording) { isRecording = false; - recordButton.setImageResource(R.drawable.ic_record_white); + item.setIcon(R.drawable.ic_record_white); CustomSnackBar.showSnackBar(mainLayout, getString(R.string.csv_store_text) + " " + csvLogger.getCurrentFilePath() , getString(R.string.open), new View.OnClickListener() { @@ -529,7 +521,7 @@ public void onClick(View view) { }, Snackbar.LENGTH_SHORT); } else { isRecording = true; - recordButton.setImageResource(R.drawable.ic_record_stop_white); + item.setIcon(R.drawable.ic_record_stop_white); block = System.currentTimeMillis(); if (gpsLogger.isGPSEnabled()) { Location location = gpsLogger.getDeviceLocation(); @@ -551,26 +543,42 @@ public void onClick(View view) { recordSensorDataBlockID(new SensorDataBlock(block, getResources().getString(R.string.oscilloscope))); CustomSnackBar.showSnackBar(mainLayout, getString(R.string.data_recording_start), null, null, Snackbar.LENGTH_SHORT); } - } - }); - - if (getIntent().getExtras() != null && getIntent().getExtras().getBoolean(KEY_LOG)) { - recordedOscilloscopeData = LocalDataLog.with() - .getBlockOfOscilloscopeRecords(getIntent().getExtras().getLong(DATA_BLOCK)); - setLayoutForPlayback(); + break; + case R.id.show_guide: + bottomSheetBehavior.setState(bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN ? + BottomSheetBehavior.STATE_EXPANDED : BottomSheetBehavior.STATE_HIDDEN); + break; + case R.id.show_logged_data: + Intent intent = new Intent(OscilloscopeActivity.this, DataLoggerActivity.class); + intent.putExtra(DataLoggerActivity.CALLER_ACTIVITY, getResources().getString(R.string.oscilloscope)); + startActivity(intent); + break; + case R.id.play_data: + if (isPlaying) { + isPlaying = false; + item.setIcon(R.drawable.ic_play_arrow_white_24dp); + pauseData(); + } else { + isPlaying = true; + item.setIcon(R.drawable.ic_pause_white_24dp); + playRecordedData(); + } + break; + default: + break; } + return true; } private void setLayoutForPlayback() { findViewById(R.id.layout_dock_os1).setVisibility(View.GONE); - recordButton.setVisibility(View.GONE); RelativeLayout.LayoutParams lineChartParams = (RelativeLayout.LayoutParams) mChartLayout.getLayoutParams(); RelativeLayout.LayoutParams frameLayoutParams = (RelativeLayout.LayoutParams) frameLayout.getLayoutParams(); - lineChartParams.height = height * 4 / 5; - lineChartParams.width = width; + lineChartParams.height = height * 3 / 4; + lineChartParams.width = RelativeLayout.LayoutParams.MATCH_PARENT; mChartLayout.setLayoutParams(lineChartParams); - frameLayoutParams.height = height / 5; - frameLayoutParams.width = width; + frameLayoutParams.height = height / 4; + frameLayoutParams.width = RelativeLayout.LayoutParams.MATCH_PARENT; frameLayout.setLayoutParams(frameLayoutParams); replaceFragment(R.id.layout_dock_os2, playbackFragment, "Playback Fragment"); } @@ -643,7 +651,7 @@ public void run() { } else { playbackTimer.cancel(); playbackTimer = null; - ((OscilloscopePlaybackFragment) playbackFragment).resetPlayButton(); + playMenu.setIcon(R.drawable.ic_play_arrow_white_24dp); currentPosition = 0; } } catch (Exception e) { @@ -651,7 +659,7 @@ public void run() { playbackTimer.cancel(); playbackTimer = null; } - ((OscilloscopePlaybackFragment) playbackFragment).resetPlayButton(); + playMenu.setIcon(R.drawable.ic_play_arrow_white_24dp); currentPosition = 0; } } @@ -662,8 +670,10 @@ public void run() { } public void pauseData() { - playbackTimer.cancel(); - playbackTimer = null; + if (playbackTimer != null) { + playbackTimer.cancel(); + playbackTimer = null; + } } private void logChannelData(String[] channels) { @@ -754,17 +764,17 @@ public void onWindowFocusChanged() { RelativeLayout.LayoutParams frameLayoutParams = (RelativeLayout.LayoutParams) frameLayout.getLayoutParams(); if (getResources().getBoolean(R.bool.isTablet)) { lineChartParams.height = height * 3 / 4; - lineChartParams.width = width * 7 / 8; + lineChartParams.width = width * 9 / 10; mChartLayout.setLayoutParams(lineChartParams); frameLayoutParams.height = height / 4; - frameLayoutParams.width = width * 7 / 8; + frameLayoutParams.width = width * 9 / 10; frameLayout.setLayoutParams(frameLayoutParams); } else { - lineChartParams.height = height * 2 / 3; - lineChartParams.width = width * 5 / 6; + lineChartParams.height = height * 3 / 5; + lineChartParams.width = width * 7 / 8; mChartLayout.setLayoutParams(lineChartParams); - frameLayoutParams.height = height / 3; - frameLayoutParams.width = width * 5 / 6; + frameLayoutParams.height = height * 2 / 5; + frameLayoutParams.width = width * 7 / 8; frameLayout.setLayoutParams(frameLayoutParams); } } @@ -1131,10 +1141,6 @@ public void run() { @Override protected void onPostExecute(Void aVoid) { super.onPostExecute(aVoid); - if (!String.valueOf(ledImageView.getTag()).equals("green")) { - ledImageView.setImageResource(R.drawable.green_led); - ledImageView.setTag("green"); - } List dataSets = new ArrayList<>(); for (int i = 0; i < Math.min(entries.size(), paramsChannels.length); i++) { diff --git a/app/src/main/java/io/pslab/activity/RoboticArmActivity.java b/app/src/main/java/io/pslab/activity/RoboticArmActivity.java index 20c9d9cfb..1bb06e6cb 100644 --- a/app/src/main/java/io/pslab/activity/RoboticArmActivity.java +++ b/app/src/main/java/io/pslab/activity/RoboticArmActivity.java @@ -14,16 +14,19 @@ import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.support.v7.widget.Toolbar; +import android.util.TypedValue; import android.view.Display; import android.view.DragEvent; import android.view.GestureDetector; import android.view.KeyEvent; import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.WindowManager; import android.view.inputmethod.EditorInfo; -import android.widget.Button; import android.widget.EditText; import android.widget.HorizontalScrollView; import android.widget.ImageView; @@ -62,7 +65,6 @@ public class RoboticArmActivity extends AppCompatActivity { private LinearLayout servo1TimeLine, servo2TimeLine, servo3TimeLine, servo4TimeLine; private int degree; private boolean editEnter = false; - private Button playPauseButton, stopButton, saveButton; private HorizontalScrollView scrollView; private CountDownTimer timeLine; private boolean isPlaying = false; @@ -76,6 +78,9 @@ public class RoboticArmActivity extends AppCompatActivity { private ScienceLab scienceLab; private BottomSheetBehavior bottomSheetBehavior; private GestureDetector gestureDetector; + private LinearLayout timeIndicatorLayout; + private LinearLayout.LayoutParams timeIndicatorParams; + private MenuItem playMenu; @BindView(R.id.sheet_slide_text_robotic_arm) TextView bottomSheetSlideText; @BindView(R.id.parent_layout_robotic) @@ -91,6 +96,13 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_robotic_arm); ButterKnife.bind(this); + Toolbar toolbar = findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + getSupportActionBar().setTitle(R.string.robotic_arm); + if (getSupportActionBar() != null) { + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowHomeEnabled(true); + } setUpBottomSheet(); parentLayout.setOnClickListener(new View.OnClickListener() { @Override @@ -108,8 +120,13 @@ public void onClick(View v) { Display display = getWindowManager().getDefaultDisplay(); Point size = new Point(); display.getSize(size); + TypedValue tv = new TypedValue(); + int actionBarHeight = 0; + if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) { + actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics()); + } int screen_width = size.x; - int screen_height = size.y; + int screen_height = size.y - actionBarHeight; realm = LocalDataLog.with().getRealm(); gpsLogger = new GPSLogger(this, (LocationManager) getSystemService(Context.LOCATION_SERVICE)); @@ -130,14 +147,10 @@ public void onClick(View v) { servo2TimeLine = findViewById(R.id.servo2_timeline); servo3TimeLine = findViewById(R.id.servo3_timeline); servo4TimeLine = findViewById(R.id.servo4_timeline); - playPauseButton = findViewById(R.id.timeline_play_pause_button); - stopButton = findViewById(R.id.timeline_stop_button); - saveButton = findViewById(R.id.timeline_save_button); scrollView = findViewById(R.id.horizontal_scroll_view); - LinearLayout timeLineControlsLayout = findViewById(R.id.servo_timeline_controls); servoCSVLogger = new CSVLogger(getResources().getString(R.string.robotic_arm)); - LinearLayout.LayoutParams servoControllerParams = new LinearLayout.LayoutParams(14 * screen_width / 60 - 4, screen_height / 2 - 4); + LinearLayout.LayoutParams servoControllerParams = new LinearLayout.LayoutParams(screen_width / 4 - 4, screen_height / 2 - 4); servoControllerParams.setMargins(2, 5, 2, 0); servo1Layout.setLayoutParams(servoControllerParams); servo2Layout.setLayoutParams(servoControllerParams); @@ -152,9 +165,6 @@ public void onClick(View v) { servo3TimeLine.setLayoutParams(servoTimeLineParams); servo4TimeLine.setLayoutParams(servoTimeLineParams); - LinearLayout.LayoutParams timeLineControlsParams = new LinearLayout.LayoutParams(screen_width / 15, screen_height / 2); - timeLineControlsLayout.setLayoutParams(timeLineControlsParams); - LinearLayout.LayoutParams servoTimeLineBoxParams = new LinearLayout.LayoutParams(screen_width / 6 - 2, screen_height / 8 - 2); servoTimeLineBoxParams.setMargins(2, 0, 0, 0); @@ -444,8 +454,8 @@ public void onClick(View v) { } }); - LinearLayout timeIndicatorLayout = findViewById(R.id.time_indicator); - LinearLayout.LayoutParams timeIndicatorParams = new LinearLayout.LayoutParams(screen_width / 6 - 2, 12); + timeIndicatorLayout = findViewById(R.id.time_indicator); + timeIndicatorParams = new LinearLayout.LayoutParams(screen_width / 6 - 2, 12); timeIndicatorParams.setMarginStart(3); timeIndicatorLayout.setLayoutParams(timeIndicatorParams); @@ -477,55 +487,12 @@ public void onFinish() { } }; - playPauseButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (isPlaying) { - isPlaying = false; - playPauseButton.setBackground(getResources().getDrawable(R.drawable.ic_play_arrow_white_24dp)); - timeLine.onFinish(); - } else { - isPlaying = true; - playPauseButton.setBackground(getResources().getDrawable(R.drawable.ic_pause_white_24dp)); - timeLine.start(); - } - } - }); - - saveButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - saveTimeline(); - } - }); - - stopButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - timeLine.cancel(); - timeIndicatorParams.setMarginStart(3); - timeIndicatorLayout.setLayoutParams(timeIndicatorParams); - scrollView.fullScroll(HorizontalScrollView.FOCUS_LEFT); - isPlaying = false; - playPauseButton.setBackground(getResources().getDrawable(R.drawable.ic_play_arrow_white_24dp)); - timelinePosition = 0; - } - }); - if (getIntent().getExtras() != null && getIntent().getExtras().getBoolean(KEY_LOG)) { recordedServoData = LocalDataLog.with() .getBlockOfServoRecords(getIntent().getExtras().getLong(DATA_BLOCK)); setReceivedData(); } - Button guideButton = findViewById(R.id.timeline_guide_button); - guideButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - bottomSheetBehavior.setState(bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN ? - BottomSheetBehavior.STATE_EXPANDED : BottomSheetBehavior.STATE_HIDDEN); - } - }); } private void setUpBottomSheet() { @@ -717,6 +684,62 @@ public boolean onDrag(View v, DragEvent event) { } }; + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.robotic_arm_menu, menu); + return true; + } + + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + playMenu = menu.findItem(R.id.play_data); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + finish(); + break; + case R.id.play_data: + if (isPlaying) { + isPlaying = false; + item.setIcon(getResources().getDrawable(R.drawable.ic_play_arrow_white_24dp)); + timeLine.onFinish(); + } else { + isPlaying = true; + item.setIcon(getResources().getDrawable(R.drawable.ic_pause_white_24dp)); + timeLine.start(); + } + break; + case R.id.stop_data: + timeLine.cancel(); + timeIndicatorParams.setMarginStart(3); + timeIndicatorLayout.setLayoutParams(timeIndicatorParams); + scrollView.fullScroll(HorizontalScrollView.FOCUS_LEFT); + isPlaying = false; + playMenu.setIcon(getResources().getDrawable(R.drawable.ic_play_arrow_white_24dp)); + timelinePosition = 0; + break; + case R.id.show_guide: + bottomSheetBehavior.setState(bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN ? + BottomSheetBehavior.STATE_EXPANDED : BottomSheetBehavior.STATE_HIDDEN); + break; + case R.id.show_logged_data: + Intent intent = new Intent(RoboticArmActivity.this, DataLoggerActivity.class); + intent.putExtra(DataLoggerActivity.CALLER_ACTIVITY, getResources().getString(R.string.robotic_arm)); + startActivity(intent); + break; + case R.id.save_data: + saveTimeline(); + break; + default: + break; + } + return true; + } + @Override protected void onResume() { super.onResume(); diff --git a/app/src/main/java/io/pslab/activity/WaveGeneratorActivity.java b/app/src/main/java/io/pslab/activity/WaveGeneratorActivity.java index 28c9ad6af..74fb11f88 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.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; +import android.graphics.Color; import android.graphics.drawable.Drawable; import android.location.Location; import android.location.LocationManager; @@ -23,6 +24,8 @@ import android.util.Log; import android.view.GestureDetector; import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.Window; @@ -34,7 +37,9 @@ import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; +import android.support.v7.widget.Toolbar; +import com.github.mikephil.charting.charts.LineChart; import com.warkiz.widget.IndicatorSeekBar; import java.util.Date; @@ -74,10 +79,6 @@ public class WaveGeneratorActivity extends AppCompatActivity { private final String MODE_SQUARE = "Square"; private final String MODE_PWM = "PWM"; //waveform monitor - @BindView(R.id.wave_mon_wave1) - TextView waveMonWave1; - @BindView(R.id.wave_mon_wave2) - TextView waveMonWave2; @BindView(R.id.wave_ic_img) ImageView selectedWaveImg; @BindView(R.id.wave_mon_select_wave) @@ -95,14 +96,6 @@ public class WaveGeneratorActivity extends AppCompatActivity { ImageView pwmSelectedModeImg; @BindView(R.id.pwm_mon_mode_select) TextView pwmMonSelectMode; - @BindView(R.id.pwm_mon_sq1) - TextView pwmMonSqr1; - @BindView(R.id.pwm_mon_sq2) - TextView pwmMonSqr2; - @BindView(R.id.pwm_mon_sq3) - TextView pwmMonSqr3; - @BindView(R.id.pwm_mon_sq4) - TextView pwmMonSqr4; @BindView(R.id.pwm_freq_value) TextView pwmFreqValue; @BindView(R.id.pwm_phase_value) @@ -135,8 +128,10 @@ public class WaveGeneratorActivity extends AppCompatActivity { Button btnPwmSq3; @BindView(R.id.pwm_btn_sq4) Button btnPwmSq4; - @BindView(R.id.pwm_btn_mode) - Button btnPwmMode; + @BindView(R.id.analog_mode_btn) + Button btnAnalogMode; + @BindView(R.id.digital_mode_btn) + Button btnDigitalMode; @BindView(R.id.pwm_btn_freq) Button pwmBtnFreq; @BindView(R.id.pwm_btn_duty) @@ -150,8 +145,6 @@ public class WaveGeneratorActivity extends AppCompatActivity { ImageButton imgBtnDown; @BindView(R.id.seek_bar_wave_gen) IndicatorSeekBar seekBar; - @BindView(R.id.btn_view) - Button btnView; //bottomSheet @BindView(R.id.bottom_sheet) LinearLayout bottomSheet; @@ -161,10 +154,10 @@ public class WaveGeneratorActivity extends AppCompatActivity { ImageView arrowUpDown; @BindView(R.id.sheet_slide_text) TextView bottomSheetSlideText; - @BindView(R.id.show_guide_wave_generator) - TextView showText; @BindView(R.id.wave_phase) TextView wavePhaseTitle; + @BindView(R.id.btn_produce_sound) + Button btnProduceSound; ScienceLab scienceLab; BottomSheetBehavior bottomSheetBehavior; GestureDetector gestureDetector; @@ -173,11 +166,9 @@ public class WaveGeneratorActivity extends AppCompatActivity { private Timer waveGenCounter; private Handler wavegenHandler = new Handler(); private AlertDialog waveDialog; - private boolean btnLongpressed; private CSVLogger csvLogger; private WaveConst waveBtnActive, pwmBtnActive, prop_active, digital_mode; private TextView activePropTv = null; - private TextView activePwmPinTv = null; private CoordinatorLayout coordinatorLayout; private Realm realm; private GPSLogger gpsLogger; @@ -186,26 +177,30 @@ public class WaveGeneratorActivity extends AppCompatActivity { private ConstraintLayout squareModeLayout; private RelativeLayout pwmModeControls; private RelativeLayout squareModeControls; + private LineChart previewChart; @SuppressLint("ClickableViewAccessibility") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - requestWindowFeature(Window.FEATURE_NO_TITLE); - getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_wave_generator_main); ButterKnife.bind(this); - removeStatusBar(); - realm = LocalDataLog.with().getRealm(); gpsLogger = new GPSLogger(this, (LocationManager) getSystemService(Context.LOCATION_SERVICE)); - + Toolbar toolbar = findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + getSupportActionBar().setTitle(getString(R.string.wave_generator)); + if (getSupportActionBar() != null) { + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowHomeEnabled(true); + } coordinatorLayout = findViewById(R.id.wave_generator_coordinator_layout); squareModeLayout = findViewById(R.id.square_mode_layout); pwmModeLayout = findViewById(R.id.pwm_mode_layout); + previewChart = findViewById(R.id.chart_preview); squareModeControls = findViewById(R.id.square_mode_controls); pwmModeControls = findViewById(R.id.pwm_mode_controls); @@ -238,15 +233,6 @@ public void onClick(View view) { } } }); - waveMonWave1.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (!waveBtnActive.equals(WaveConst.WAVE1)) { - waveMonSelected = true; - selectBtn(WaveConst.WAVE1); - } - } - }); btnCtrlWave2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -256,20 +242,11 @@ public void onClick(View view) { } } }); - waveMonWave2.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (!waveBtnActive.equals(WaveConst.WAVE2)) { - waveMonSelected = true; - selectBtn(WaveConst.WAVE2); - } - } - }); imgBtnSin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - imgBtnSin.setVisibility(View.GONE); - imgBtnTri.setVisibility(View.VISIBLE); + imgBtnSin.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded)); + imgBtnTri.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded_light)); WaveGeneratorCommon.wave.get(waveBtnActive).put(WaveConst.WAVETYPE, SIN); selectWaveform(SIN); } @@ -278,8 +255,8 @@ public void onClick(View view) { imgBtnTri.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - imgBtnSin.setVisibility(View.VISIBLE); - imgBtnTri.setVisibility(View.GONE); + imgBtnSin.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded_light)); + imgBtnTri.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded)); WaveGeneratorCommon.wave.get(waveBtnActive).put(WaveConst.WAVETYPE, TRIANGULAR); selectWaveform(TRIANGULAR); } @@ -294,6 +271,8 @@ public void onClick(View view) { activePropTv = waveFreqValue; waveMonPropSelect.setText(getString(R.string.wave_frequency)); setSeekBar(seekBar); + btnCtrlFreq.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded)); + btnCtrlPhase.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded_light)); } }); @@ -306,34 +285,40 @@ public void onClick(View view) { activePropTv = wavePhaseValue; waveMonPropSelect.setText(getString(R.string.phase_offset)); setSeekBar(seekBar); + btnCtrlFreq.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded_light)); + btnCtrlPhase.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded)); } }); - //pwm panel - btnPwmMode.setOnClickListener(new View.OnClickListener() { + btnAnalogMode.setOnClickListener(new View.OnClickListener() { @Override - public void onClick(View view) { - WaveGeneratorCommon.intializeDigitalValue(); - if (digital_mode == WaveConst.SQUARE) { - pwmModeLayout.setVisibility(View.VISIBLE); - pwmModeControls.setVisibility(View.VISIBLE); - squareModeLayout.setVisibility(View.GONE); - squareModeControls.setVisibility(View.GONE); - toggleDigitalMode(WaveConst.PWM); - imgBtnSin.setEnabled(false); - imgBtnTri.setEnabled(false); - pwmBtnActive = WaveConst.SQR1; - selectBtn(WaveConst.SQR1); - Toast.makeText(WaveGeneratorActivity.this, R.string.wave_pin_disable_comment, Toast.LENGTH_SHORT).show(); - } else { - pwmModeLayout.setVisibility(View.GONE); - pwmModeControls.setVisibility(View.GONE); - squareModeLayout.setVisibility(View.VISIBLE); - squareModeControls.setVisibility(View.VISIBLE); - imgBtnSin.setEnabled(true); - imgBtnTri.setEnabled(true); - toggleDigitalMode(WaveConst.SQUARE); - } + public void onClick(View v) { + pwmModeLayout.setVisibility(View.GONE); + pwmModeControls.setVisibility(View.GONE); + squareModeLayout.setVisibility(View.VISIBLE); + squareModeControls.setVisibility(View.VISIBLE); + imgBtnSin.setEnabled(true); + imgBtnTri.setEnabled(true); + toggleDigitalMode(WaveConst.SQUARE); + btnDigitalMode.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded_light)); + btnAnalogMode.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded)); + } + }); + + btnDigitalMode.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + pwmModeLayout.setVisibility(View.VISIBLE); + pwmModeControls.setVisibility(View.VISIBLE); + squareModeLayout.setVisibility(View.GONE); + squareModeControls.setVisibility(View.GONE); + toggleDigitalMode(WaveConst.PWM); + imgBtnSin.setEnabled(false); + imgBtnTri.setEnabled(false); + pwmBtnActive = WaveConst.SQR1; + selectBtn(WaveConst.SQR1); + btnDigitalMode.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded)); + btnAnalogMode.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded_light)); } }); @@ -386,6 +371,9 @@ public void onClick(View view) { activePropTv = pwmFreqValue; pwmMonPropSelect.setText(getString(R.string.frequecy_colon)); setSeekBar(seekBar); + pwmBtnFreq.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded)); + pwmBtnPhase.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded_light)); + pwmBtnDuty.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded_light)); } }); @@ -398,6 +386,9 @@ public void onClick(View view) { activePropTv = pwmPhaseValue; pwmMonPropSelect.setText(getString(R.string.pwm_phase)); setSeekBar(seekBar); + pwmBtnFreq.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded_light)); + pwmBtnPhase.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded)); + pwmBtnDuty.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded_light)); } }); @@ -410,6 +401,9 @@ public void onClick(View view) { activePropTv = pwmDutyValue; pwmMonPropSelect.setText(getString(R.string.duty_cycle)); setSeekBar(seekBar); + pwmBtnFreq.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded_light)); + pwmBtnPhase.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded_light)); + pwmBtnDuty.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded)); } }); @@ -417,53 +411,10 @@ public void onClick(View view) { monitorLongClicks(imgBtnUp, imgBtnDown); - btnView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - double freq1 = (double) (WaveGeneratorCommon.wave.get(WaveConst.WAVE1).get(WaveConst.FREQUENCY)); - double freq2 = (double) WaveGeneratorCommon.wave.get(WaveConst.WAVE2).get(WaveConst.FREQUENCY); - double phase = (double) WaveGeneratorCommon.wave.get(WaveConst.WAVE2).get(WaveConst.PHASE); - - String waveType1 = WaveGeneratorCommon.wave.get(WaveConst.WAVE1).get(WaveConst.WAVETYPE) == SIN ? "sine" : "tria"; - String waveType2 = WaveGeneratorCommon.wave.get(WaveConst.WAVE2).get(WaveConst.WAVETYPE) == SIN ? "sine" : "tria"; - - if (scienceLab.isConnected()) { - if (digital_mode == WaveConst.SQUARE) { - if (phase == WaveData.PHASE_MIN.getValue()) { - scienceLab.setW1(freq1, waveType1); - scienceLab.setW2(freq2, waveType2); - } else { - scienceLab.setWaves(freq1, phase, freq2); - } - } else { - double freqSqr1 = (double) WaveGeneratorCommon.wave.get(WaveConst.SQR1).get(WaveConst.FREQUENCY); - double dutySqr1 = (double) WaveGeneratorCommon.wave.get(WaveConst.SQR1).get(WaveConst.DUTY) / 100; - double dutySqr2 = ((double) WaveGeneratorCommon.wave.get(WaveConst.SQR2).get(WaveConst.DUTY)) / 100; - double phaseSqr2 = (double) WaveGeneratorCommon.wave.get(WaveConst.SQR2).get(WaveConst.PHASE) / 360; - double dutySqr3 = ((double) WaveGeneratorCommon.wave.get(WaveConst.SQR3).get(WaveConst.DUTY)) / 100; - double phaseSqr3 = (double) WaveGeneratorCommon.wave.get(WaveConst.SQR3).get(WaveConst.PHASE) / 360; - double dutySqr4 = ((double) WaveGeneratorCommon.wave.get(WaveConst.SQR4).get(WaveConst.DUTY)) / 100; - double phaseSqr4 = (double) WaveGeneratorCommon.wave.get(WaveConst.SQR4).get(WaveConst.PHASE) / 360; - - scienceLab.sqrPWM(freqSqr1, dutySqr1, phaseSqr2, dutySqr2, phaseSqr3, dutySqr3, phaseSqr4, dutySqr4, false); - } - - waveDialog.show(); - Window window = waveDialog.getWindow(); - window.setLayout(dpToPx(350), dpToPx(300)); - waveDialog.getButton(DialogInterface.BUTTON_NEGATIVE) - .setTextColor(ContextCompat.getColor(WaveGeneratorActivity.this, R.color.colorPrimary)); - - } else { - Toast.makeText(WaveGeneratorActivity.this, R.string.device_not_connected, Toast.LENGTH_SHORT).show(); - } - } - }); - seekBar.setOnSeekChangeListener(new IndicatorSeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(IndicatorSeekBar seekBar, int progress, float progressFloat, boolean fromUserTouch) { - String valueText = DataFormatter.formatDouble((float) progress, DataFormatter.MEDIUM_PRECISION_FORMAT) + " " + unit; + String valueText = progress + " " + unit; if (waveMonSelected) { waveMonPropValueSelect.setText(valueText); } else { @@ -488,44 +439,15 @@ public void onStopTrackingTouch(IndicatorSeekBar seekBar) { } }); - ImageView guideImageView = findViewById(R.id.wave_generator_guide_button); - guideImageView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - bottomSheetBehavior.setState(bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN ? - BottomSheetBehavior.STATE_EXPANDED : BottomSheetBehavior.STATE_HIDDEN); - } - }); - guideImageView.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - showText.setVisibility(View.VISIBLE); - btnLongpressed = true; - return true; - } - }); - guideImageView.setOnTouchListener(new View.OnTouchListener() { - @Override - public boolean onTouch(View v, MotionEvent event) { - v.onTouchEvent(event); - if (event.getAction() == MotionEvent.ACTION_UP) { - if (btnLongpressed) { - showText.setVisibility(View.GONE); - btnLongpressed = false; - } - } - return true; - } - }); - if (getIntent().getExtras() != null && getIntent().getExtras().getBoolean(KEY_LOG)) { recordedWaveData = LocalDataLog.with() .getBlockOfWaveRecords(getIntent().getExtras().getLong(DATA_BLOCK)); setReceivedData(); } + chartInit(); } - public void saveWaveConfig(View view) { + public void saveWaveConfig() { long block = System.currentTimeMillis(); csvLogger.prepareLogFile(); csvLogger.writeMetaData(getResources().getString(R.string.wave_generator)); @@ -649,27 +571,87 @@ public void setReceivedData() { } } + private void setWave() { + double freq1 = (double) (WaveGeneratorCommon.wave.get(WaveConst.WAVE1).get(WaveConst.FREQUENCY)); + double freq2 = (double) WaveGeneratorCommon.wave.get(WaveConst.WAVE2).get(WaveConst.FREQUENCY); + double phase = (double) WaveGeneratorCommon.wave.get(WaveConst.WAVE2).get(WaveConst.PHASE); + + String waveType1 = WaveGeneratorCommon.wave.get(WaveConst.WAVE1).get(WaveConst.WAVETYPE) == SIN ? "sine" : "tria"; + String waveType2 = WaveGeneratorCommon.wave.get(WaveConst.WAVE2).get(WaveConst.WAVETYPE) == SIN ? "sine" : "tria"; + + if (scienceLab.isConnected()) { + if (digital_mode == WaveConst.SQUARE) { + if (phase == WaveData.PHASE_MIN.getValue()) { + scienceLab.setW1(freq1, waveType1); + scienceLab.setW2(freq2, waveType2); + } else { + scienceLab.setWaves(freq1, phase, freq2); + } + } else { + double freqSqr1 = (double) WaveGeneratorCommon.wave.get(WaveConst.SQR1).get(WaveConst.FREQUENCY); + double dutySqr1 = (double) WaveGeneratorCommon.wave.get(WaveConst.SQR1).get(WaveConst.DUTY) / 100; + double dutySqr2 = ((double) WaveGeneratorCommon.wave.get(WaveConst.SQR2).get(WaveConst.DUTY)) / 100; + double phaseSqr2 = (double) WaveGeneratorCommon.wave.get(WaveConst.SQR2).get(WaveConst.PHASE) / 360; + double dutySqr3 = ((double) WaveGeneratorCommon.wave.get(WaveConst.SQR3).get(WaveConst.DUTY)) / 100; + double phaseSqr3 = (double) WaveGeneratorCommon.wave.get(WaveConst.SQR3).get(WaveConst.PHASE) / 360; + double dutySqr4 = ((double) WaveGeneratorCommon.wave.get(WaveConst.SQR4).get(WaveConst.DUTY)) / 100; + double phaseSqr4 = (double) WaveGeneratorCommon.wave.get(WaveConst.SQR4).get(WaveConst.PHASE) / 360; + + scienceLab.sqrPWM(freqSqr1, dutySqr1, phaseSqr2, dutySqr2, phaseSqr3, dutySqr3, phaseSqr4, dutySqr4, false); + } + + } + } + + private void viewWaveDialog() { + waveDialog.show(); + Window window = waveDialog.getWindow(); + window.setLayout(dpToPx(350), dpToPx(300)); + waveDialog.getButton(DialogInterface.BUTTON_NEGATIVE) + .setTextColor(ContextCompat.getColor(WaveGeneratorActivity.this, R.color.colorPrimary)); + } + @Override - protected void onResume() { - super.onResume(); - removeStatusBar(); + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.wave_generator_menu, menu); + return true; } - private void removeStatusBar() { - 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)); + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + finish(); + break; + case R.id.save_data: + saveWaveConfig(); + break; + case R.id.play_data: + setWave(); + if (scienceLab.isConnected()) { + viewWaveDialog(); + } else { + Toast.makeText(WaveGeneratorActivity.this, R.string.device_not_connected, Toast.LENGTH_SHORT).show(); + } + break; + case R.id.show_guide: + bottomSheetBehavior.setState(bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN ? + BottomSheetBehavior.STATE_EXPANDED : BottomSheetBehavior.STATE_HIDDEN); + break; + case R.id.show_logged_data: + Intent intent = new Intent(WaveGeneratorActivity.this, DataLoggerActivity.class); + intent.putExtra(DataLoggerActivity.CALLER_ACTIVITY, getString(R.string.wave_generator)); + startActivity(intent); + break; + default: + break; } + return true; + } + + @Override + protected void onResume() { + super.onResume(); } public void selectBtn(WaveConst btn_selected) { @@ -680,8 +662,8 @@ public void selectBtn(WaveConst btn_selected) { waveBtnActive = WaveConst.WAVE1; - waveMonWave1.setTextColor(getResources().getColor(R.color.orange)); - waveMonWave2.setTextColor(getResources().getColor(R.color.dark_grey)); + btnCtrlWave1.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded)); + btnCtrlWave2.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded_light)); btnCtrlPhase.setEnabled(false); //disable phase for wave wavePhaseValue.setText("--"); @@ -696,8 +678,8 @@ public void selectBtn(WaveConst btn_selected) { waveBtnActive = WaveConst.WAVE2; - waveMonWave2.setTextColor(getResources().getColor(R.color.orange)); - waveMonWave1.setTextColor(getResources().getColor(R.color.dark_grey)); + btnCtrlWave2.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded)); + btnCtrlWave1.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded_light)); btnCtrlPhase.setEnabled(true); // enable phase for wave2 @@ -709,10 +691,11 @@ public void selectBtn(WaveConst btn_selected) { break; case SQR1: - activePwmPinTv.setEnabled(false); pwmBtnActive = WaveConst.SQR1; - activePwmPinTv = pwmMonSqr1; - activePwmPinTv.setEnabled(true); + btnPwmSq1.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded)); + btnPwmSq2.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded_light)); + btnPwmSq3.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded_light)); + btnPwmSq4.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded_light)); pwmBtnPhase.setEnabled(false); //phase disabled for sq1 pwmPhaseValue.setText("--"); fetchPropertyValue(pwmBtnActive, WaveConst.FREQUENCY, getString(R.string.unit_hz), pwmFreqValue); @@ -721,10 +704,11 @@ public void selectBtn(WaveConst btn_selected) { case SQR2: - activePwmPinTv.setEnabled(false); pwmBtnActive = WaveConst.SQR2; - activePwmPinTv = pwmMonSqr2; - activePwmPinTv.setEnabled(true); + btnPwmSq1.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded_light)); + btnPwmSq2.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded)); + btnPwmSq3.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded_light)); + btnPwmSq4.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded_light)); pwmBtnPhase.setEnabled(true); fetchPropertyValue(pwmBtnActive, WaveConst.PHASE, getString(R.string.deg_text), pwmPhaseValue); fetchPropertyValue(pwmBtnActive, WaveConst.DUTY, getString(R.string.unit_percent), pwmDutyValue); @@ -732,10 +716,11 @@ public void selectBtn(WaveConst btn_selected) { case SQR3: - activePwmPinTv.setEnabled(false); pwmBtnActive = WaveConst.SQR3; - activePwmPinTv = pwmMonSqr3; - activePwmPinTv.setEnabled(true); + btnPwmSq1.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded_light)); + btnPwmSq2.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded_light)); + btnPwmSq3.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded)); + btnPwmSq4.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded_light)); pwmBtnPhase.setEnabled(true); fetchPropertyValue(pwmBtnActive, WaveConst.PHASE, getString(R.string.deg_text), pwmPhaseValue); fetchPropertyValue(pwmBtnActive, WaveConst.DUTY, getString(R.string.unit_percent), pwmDutyValue); @@ -743,10 +728,11 @@ public void selectBtn(WaveConst btn_selected) { case SQR4: - activePwmPinTv.setEnabled(false); pwmBtnActive = WaveConst.SQR4; - activePwmPinTv = pwmMonSqr4; - activePwmPinTv.setEnabled(true); + btnPwmSq1.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded_light)); + btnPwmSq2.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded_light)); + btnPwmSq3.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded_light)); + btnPwmSq4.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded)); pwmBtnPhase.setEnabled(true); fetchPropertyValue(pwmBtnActive, WaveConst.PHASE, getString(R.string.deg_text), pwmPhaseValue); fetchPropertyValue(pwmBtnActive, WaveConst.DUTY, getString(R.string.unit_percent), pwmDutyValue); @@ -754,8 +740,8 @@ public void selectBtn(WaveConst btn_selected) { default: waveBtnActive = WaveConst.WAVE1; - waveMonWave1.setTextColor(getResources().getColor(R.color.orange)); - waveMonWave2.setTextColor(getResources().getColor(R.color.dark_grey)); + btnCtrlWave1.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded)); + btnCtrlWave2.setBackground(getResources().getDrawable(R.drawable.btn_back_rounded_light)); btnCtrlPhase.setEnabled(false); //disable phase for wave wavePhaseValue.setText("--"); selectWaveform(WaveGeneratorCommon.wave.get(waveBtnActive).get(WaveConst.WAVETYPE)); @@ -813,16 +799,12 @@ private void toggleDigitalMode(WaveConst mode) { btnPwmSq3.setEnabled(true); btnPwmSq4.setEnabled(true); } - pwmMonSqr1.setSelected(false); - pwmMonSqr2.setSelected(false); - pwmMonSqr3.setSelected(false); - pwmMonSqr4.setSelected(false); WaveGeneratorCommon.mode_selected = mode; } private void fetchPropertyValue(WaveConst btnActive, WaveConst property, String unit, TextView propTextView) { Double value = (double) WaveGeneratorCommon.wave.get(btnActive).get(property); - String valueText = value + " " + unit; + String valueText = value.intValue() + " " + unit; propTextView.setText(valueText); } @@ -914,11 +896,29 @@ private void setValue() { } else { WaveGeneratorCommon.wave.get(waveBtnActive).put(prop_active, value); } - + setWave(); Double dValue = (double) value; - String valueText = DataFormatter.formatDouble(dValue, DataFormatter.MEDIUM_PRECISION_FORMAT) + " " + unit; + String valueText = String.valueOf(dValue.intValue()) + " " + unit; activePropTv.setText(valueText); + } + private void chartInit() { + previewChart.setTouchEnabled(true); + previewChart.setHighlightPerDragEnabled(true); + previewChart.setDragEnabled(true); + previewChart.setScaleEnabled(true); + previewChart.setDrawGridBackground(false); + previewChart.setPinchZoom(true); + previewChart.setScaleYEnabled(false); + previewChart.setBackgroundColor(Color.BLACK); + previewChart.getDescription().setEnabled(false); + previewChart.getXAxis().setAxisMaximum(1000); + previewChart.getXAxis().setAxisMinimum(0); + previewChart.getXAxis().setTextColor(Color.WHITE); + previewChart.getAxisLeft().setAxisMaximum(5); + previewChart.getAxisLeft().setAxisMinimum(-5); + previewChart.fitScreen(); + previewChart.invalidate(); } private void toggleSeekBtns(boolean state) { @@ -935,13 +935,11 @@ private void toggleSeekBtns(boolean state) { private void enableInitialState() { selectBtn(WaveConst.WAVE1); - activePwmPinTv = pwmMonSqr1; toggleDigitalMode(WaveConst.SQUARE); } private void enableInitialStatePWM() { selectBtn(WaveConst.SQR2); - activePwmPinTv = pwmMonSqr2; toggleDigitalMode(WaveConst.PWM); } diff --git a/app/src/main/java/io/pslab/communication/HttpAsyncTask.java b/app/src/main/java/io/pslab/communication/HttpAsyncTask.java new file mode 100644 index 000000000..4aae41545 --- /dev/null +++ b/app/src/main/java/io/pslab/communication/HttpAsyncTask.java @@ -0,0 +1,43 @@ +package io.pslab.communication; + +import android.os.AsyncTask; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.IOException; + +import io.pslab.interfaces.HttpCallback; + +public class HttpAsyncTask extends AsyncTask { + + private HttpHandler mHttpHandler; + private HttpCallback mHttpCallback; + + public HttpAsyncTask(String baseIP, HttpCallback httpCallback) { + mHttpHandler = new HttpHandler(baseIP); + mHttpCallback = httpCallback; + } + + @Override + protected Void doInBackground(byte[]... data) { + int res = 0; + try { + if (data.length != 0) { + res = mHttpHandler.write(data[0]); + + } else { + res = mHttpHandler.read(); + } + } catch (IOException | JSONException e) { + mHttpCallback.error(e); + e.printStackTrace(); + } + if (res == 1) { + mHttpCallback.success(mHttpHandler.getReceivedData()); + } else { + mHttpCallback.error(new Exception()); + } + return null; + } +} diff --git a/app/src/main/java/io/pslab/communication/HttpHandler.java b/app/src/main/java/io/pslab/communication/HttpHandler.java new file mode 100644 index 000000000..a2f7bed38 --- /dev/null +++ b/app/src/main/java/io/pslab/communication/HttpHandler.java @@ -0,0 +1,87 @@ +package io.pslab.communication; + +import android.util.Log; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.IOException; +import java.net.URL; + +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; + +public class HttpHandler { + + private final String TAG = this.getClass().getSimpleName(); + private String baseIP; + private String sendDataEndPoint = "send"; + private String getDataEndPoint = "get"; + private String dataKeyString = "data"; + private OkHttpClient client; + private JSONObject receivedData; + + public HttpHandler(String baseIP) { + this.baseIP = baseIP; + this.client = new OkHttpClient(); + } + + /** + * Method to send data to ESP + * + * @param data data to be sent in byte array + * @return 1 if response code is "200" 0 otherwise; + */ + public int write(byte[] data) throws IOException, JSONException { + int result = 1; + URL baseURL = new URL("http://" + baseIP + "/" + sendDataEndPoint); + int written = 0; + JSONArray responseArray = new JSONArray(); + while (written < data.length) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(dataKeyString, data[written]); + RequestBody body = RequestBody.create(jsonObject.toString(), MediaType.get("application/json; charset=utf-8")); + Request request = new Request.Builder() + .url(baseURL) + .post(body) + .build(); + Response response = client.newCall(request).execute(); + responseArray.put(new JSONObject(response.body().string())); + if (response.code() != 200) { + Log.e(TAG, "Error writing byte:" + written); + return 0; + } + written++; + } + receivedData = new JSONObject(responseArray.toString()); + return result; + } + + /** + * Method to get data from ESP + * @return 1 if data was received 0 otherwise + */ + public int read() throws IOException, JSONException { + int result = 1; + URL baseURL = new URL("http://" + baseIP + "/" + getDataEndPoint); + Request request = new Request.Builder() + .url(baseURL) + .build(); + Response response = client.newCall(request).execute(); + if (response.code() != 200) { + Log.e(TAG, "Error reading data"); + return 0; + } else { + receivedData = new JSONObject(response.body().string()); + } + return result; + } + + public JSONObject getReceivedData() { + return receivedData; + } +} diff --git a/app/src/main/java/io/pslab/communication/PacketHandler.java b/app/src/main/java/io/pslab/communication/PacketHandler.java index 2cfa87b1c..49522aed9 100644 --- a/app/src/main/java/io/pslab/communication/PacketHandler.java +++ b/app/src/main/java/io/pslab/communication/PacketHandler.java @@ -2,12 +2,18 @@ import android.util.Log; +import org.json.JSONException; +import org.json.JSONObject; + import java.io.IOException; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.charset.Charset; import java.util.Arrays; +import io.pslab.interfaces.HttpCallback; +import io.pslab.others.ScienceLabCommon; + /** * Created by viveksb007 on 28/3/17. */ @@ -24,6 +30,7 @@ public class PacketHandler { private CommandsProto mCommandsProto; private int timeout = 500, VERSION_STRING_LENGTH = 15; ByteBuffer burstBuffer = ByteBuffer.allocate(2000); + private HttpAsyncTask httpAsyncTask; public PacketHandler(int timeout, CommunicationHandler communicationHandler) { this.loadBurst = false; @@ -31,11 +38,11 @@ public PacketHandler(int timeout, CommunicationHandler communicationHandler) { this.timeout = timeout; this.mCommandsProto = new CommandsProto(); this.mCommunicationHandler = communicationHandler; - connected = mCommunicationHandler.isConnected(); + connected = (mCommunicationHandler.isConnected() || ScienceLabCommon.isWifiConnected()); } public boolean isConnected() { - connected = mCommunicationHandler.isConnected(); + connected = (mCommunicationHandler.isConnected() || ScienceLabCommon.isWifiConnected()); return connected; } @@ -44,7 +51,7 @@ public String getVersion() { sendByte(mCommandsProto.COMMON); sendByte(mCommandsProto.GET_VERSION); // Read "\n" - mCommunicationHandler.read(buffer, VERSION_STRING_LENGTH + 1, timeout); + commonRead(VERSION_STRING_LENGTH + 1); version = new String(Arrays.copyOfRange(buffer, 0, VERSION_STRING_LENGTH), Charset.forName("UTF-8")); } catch (IOException e) { Log.e("Error in Communication", e.toString()); @@ -58,7 +65,7 @@ public void sendByte(int val) throws IOException { } if (!loadBurst) { try { - mCommunicationHandler.write(new byte[]{(byte) (val & 0xff)}, timeout); + commonWrite(new byte[]{(byte) (val & 0xff)}); } catch (IOException | NullPointerException e) { Log.e("Error in sending byte", e.toString()); e.printStackTrace(); @@ -74,7 +81,7 @@ public void sendInt(int val) throws IOException { } if (!loadBurst) { try { - mCommunicationHandler.write(new byte[]{(byte) (val & 0xff), (byte) ((val >> 8) & 0xff)}, timeout); + commonWrite(new byte[]{(byte) (val & 0xff), (byte) ((val >> 8) & 0xff)}); } catch (IOException e) { Log.e("Error in sending int", e.toString()); e.printStackTrace(); @@ -97,7 +104,7 @@ public int getAcknowledgement() { return 1; } else { try { - mCommunicationHandler.read(buffer, 1, timeout); + commonRead(1); return buffer[0]; } catch (IOException | NullPointerException e) { e.printStackTrace(); @@ -108,7 +115,7 @@ public int getAcknowledgement() { public byte getByte() { try { - int numByteRead = mCommunicationHandler.read(buffer, 1, timeout); + int numByteRead = commonRead(1); if (numByteRead == 1) { return buffer[0]; } else { @@ -123,7 +130,7 @@ public byte getByte() { int getVoltageSummation() { try { // Note : bytesToBeRead has to be +1 than the requirement - int numByteRead = mCommunicationHandler.read(buffer, 3, timeout); + int numByteRead = commonRead(3); if (numByteRead == 3) { return (buffer[0] & 0xff) | ((buffer[1] << 8) & 0xff00); } else { @@ -137,7 +144,7 @@ int getVoltageSummation() { public int getInt() { try { - int numByteRead = mCommunicationHandler.read(buffer, 2, timeout); + int numByteRead = commonRead(2); if (numByteRead == 2) { // LSB is read first return (buffer[0] & 0xff) | ((buffer[1] << 8) & 0xff00); @@ -152,7 +159,7 @@ public int getInt() { public long getLong() { try { - int numByteRead = mCommunicationHandler.read(buffer, 4, timeout); + int numByteRead = commonRead(4); if (numByteRead == 4) { // C++ has long of 4-bytes but in Java int has 4-bytes // refer "https://stackoverflow.com/questions/7619058/convert-a-byte-array-to-integer-in-java-and-vice-versa" for Endian @@ -171,7 +178,7 @@ public boolean waitForData() { } public int read(byte[] dest, int bytesToRead) throws IOException { - int numBytesRead = mCommunicationHandler.read(buffer, bytesToRead, timeout); + int numBytesRead = commonRead(bytesToRead); for (int i = 0; i < bytesToRead; i++) { dest[i] = buffer[i]; } @@ -185,10 +192,10 @@ public int read(byte[] dest, int bytesToRead) throws IOException { public byte[] sendBurst() { try { - mCommunicationHandler.write(burstBuffer.array(), timeout); + commonWrite(burstBuffer.array()); burstBuffer.clear(); loadBurst = false; - int bytesRead = mCommunicationHandler.read(buffer, inputQueueSize, timeout); + int bytesRead = commonRead(inputQueueSize); inputQueueSize = 0; return Arrays.copyOfRange(buffer, 0, bytesRead); } catch (IOException e) { @@ -197,4 +204,51 @@ public byte[] sendBurst() { return new byte[]{-1}; } + private int commonRead(int bytesToRead) throws IOException { + final int[] bytesRead = {0}; + if (mCommunicationHandler.isConnected()) { + bytesRead[0] = mCommunicationHandler.read(buffer, bytesToRead, timeout); + } else if (ScienceLabCommon.isWifiConnected()) { + httpAsyncTask = new HttpAsyncTask(ScienceLabCommon.getEspIP(), new HttpCallback() { + @Override + public void success(JSONObject jsonObject) { + try { + //Server will send byte array + buffer = (byte[])jsonObject.get("data"); + bytesRead[0] = buffer.length; + } catch (JSONException e) { + e.printStackTrace(); + } + } + + @Override + public void error(Exception e) { + Log.e(TAG, "Error reading data over ESP"); + } + }); + httpAsyncTask.execute(new byte[]{}); + } + return bytesRead[0]; + } + + private void commonWrite(byte[] data) throws IOException { + if (mCommunicationHandler.isConnected()) { + mCommunicationHandler.write(data, timeout); + } else if (ScienceLabCommon.isWifiConnected()) { + httpAsyncTask = new HttpAsyncTask(ScienceLabCommon.getEspIP(), new HttpCallback() { + @Override + public void success(JSONObject jsonObject) { + Log.v(TAG, "write response:" + jsonObject.toString()); + } + + @Override + public void error(Exception e) { + Log.e(TAG, "Error writing data over ESP"); + } + }); + + httpAsyncTask.execute(data); + } + + } } diff --git a/app/src/main/java/io/pslab/fragment/AboutUsFragment.java b/app/src/main/java/io/pslab/fragment/AboutUsFragment.java index 2c4b661f7..9cf812625 100644 --- a/app/src/main/java/io/pslab/fragment/AboutUsFragment.java +++ b/app/src/main/java/io/pslab/fragment/AboutUsFragment.java @@ -16,6 +16,7 @@ import butterknife.BindView; import butterknife.ButterKnife; import mehdi.sakout.aboutpage.AboutPage; +import mehdi.sakout.aboutpage.Element; /** * Created by Abhinav on 12-05-2018. @@ -43,6 +44,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, View aboutPage = new AboutPage(getActivity()) .isRTL(false) .setImage(R.drawable.logo200x200) + .addWebsite("https://goo.gl/forms/sHlmRAPFmzcGQ27u2", getString(R.string.nav_report)) + .addItem(new Element(getString(R.string.version), R.drawable.ic_widgets_black_24dp)) + .addItem(new Element(getString(R.string.flavor), R.drawable.ic_android_black_24dp)) .setDescription(getString(R.string.about_us_description)) .addGroup("Connect with us") .addEmail("pslab-fossasia@googlegroups.com") diff --git a/app/src/main/java/io/pslab/fragment/BluetoothScanFragment.java b/app/src/main/java/io/pslab/fragment/BluetoothScanFragment.java index aedb71c8a..0af19d397 100644 --- a/app/src/main/java/io/pslab/fragment/BluetoothScanFragment.java +++ b/app/src/main/java/io/pslab/fragment/BluetoothScanFragment.java @@ -42,10 +42,12 @@ public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (BluetoothDevice.ACTION_FOUND.equals(action)) { BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); - String deviceName = device.getName(); - deviceList.add(deviceName); - bluetoothDevices.add(device); - deviceListAdapter.notifyDataSetChanged(); + if (device != null) { + String deviceName = device.getName(); + deviceList.add(deviceName); + bluetoothDevices.add(device); + deviceListAdapter.notifyDataSetChanged(); + } } } }; diff --git a/app/src/main/java/io/pslab/fragment/ChannelParametersFragment.java b/app/src/main/java/io/pslab/fragment/ChannelParametersFragment.java index 4d629c99f..41f4a9420 100644 --- a/app/src/main/java/io/pslab/fragment/ChannelParametersFragment.java +++ b/app/src/main/java/io/pslab/fragment/ChannelParametersFragment.java @@ -21,7 +21,6 @@ import io.pslab.DataFormatter; import io.pslab.R; import io.pslab.activity.OscilloscopeActivity; -import io.pslab.others.NothingSelectedSpinnerAdapter; public class ChannelParametersFragment extends Fragment { @@ -30,13 +29,11 @@ public class ChannelParametersFragment extends Fragment { private CheckBox checkBoxCH1; private CheckBox checkBoxCH2; private CheckBox checkBoxCH3; - private CheckBox checkBoxMIC; private Spinner spinnerRangeCh1; private Spinner spinnerRangeCh2; private Spinner spinnerChannelSelect; - private Spinner spinnerMICSelect; - private int micSelectedPosition; - + private CheckBox builtInMicCheckBox; + private CheckBox pslabMicCheckBox; public static ChannelParametersFragment newInstance() { return new ChannelParametersFragment(); @@ -56,15 +53,15 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, spinnerRangeCh1 = v.findViewById(R.id.spinner_range_ch1_cp); spinnerRangeCh2 = v.findViewById(R.id.spinner_range_ch2_cp); spinnerChannelSelect = v.findViewById(R.id.spinner_channel_select_cp); - spinnerMICSelect = v.findViewById(R.id.spinner_mic_select_cp); boolean tabletSize = getResources().getBoolean(R.bool.isTablet); checkBoxCH1 = v.findViewById(R.id.checkBox_ch1_cp); checkBoxCH2 = v.findViewById(R.id.checkBox_ch2_cp); checkBoxCH3 = v.findViewById(R.id.checkBox_ch3_cp); checkBoxCH3.setText(getString(R.string.ch3_value, 3.3)); - checkBoxMIC = v.findViewById(R.id.checkBox_mic_cp); + builtInMicCheckBox = v.findViewById(R.id.built_in_mic_cb); + pslabMicCheckBox = v.findViewById(R.id.pslab_mic_cb); ArrayAdapter rangesAdapter; ArrayAdapter channelsAdapter; ArrayAdapter micsAdapter; @@ -88,9 +85,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, spinnerRangeCh2.setSelection(rangesAdapter.getPosition("+/-16V"), true); spinnerChannelSelect.setAdapter(channelsAdapter); spinnerChannelSelect.setSelection(channelsAdapter.getPosition("CH1"), true); - spinnerMICSelect.setAdapter(new NothingSelectedSpinnerAdapter(micsAdapter, - R.layout.nothing_selected_spinner_row, - getActivity())); spinnerRangeCh1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override @@ -220,31 +214,6 @@ public void onNothingSelected(AdapterView parent) { } }); - spinnerMICSelect.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { - @Override - public void onItemSelected(AdapterView parent, View view, int position, long id) { - micSelectedPosition = position; - if (position == 1) { - ((OscilloscopeActivity) getActivity()).isInBuiltMicSelected = false; - if (checkBoxMIC.isChecked()) { - ((OscilloscopeActivity) getActivity()).isMICSelected = true; - ((OscilloscopeActivity) getActivity()).isAudioInputSelected = true; - } - } else { - ((OscilloscopeActivity) getActivity()).isMICSelected = false; - if (checkBoxMIC.isChecked()) { - ((OscilloscopeActivity) getActivity()).isInBuiltMicSelected = true; - ((OscilloscopeActivity) getActivity()).isAudioInputSelected = true; - } - } - } - - @Override - public void onNothingSelected(AdapterView parent) { - - } - }); - checkBoxCH1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { @@ -265,29 +234,37 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { ((OscilloscopeActivity) getActivity()).isCH3Selected = isChecked; } }); - checkBoxMIC.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + builtInMicCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (micSelectedPosition == 1) { - ((OscilloscopeActivity) getActivity()).isAudioInputSelected = isChecked; - ((OscilloscopeActivity) getActivity()).isMICSelected = isChecked; - } else if (micSelectedPosition == 2) { - ((OscilloscopeActivity) getActivity()).isAudioInputSelected = isChecked; - // check for RECORD_AUDIO permission if has then change boolean - if (isChecked) - if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) { - requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, RECORD_AUDIO_REQUEST_CODE); - } else { - ((OscilloscopeActivity) getActivity()).isInBuiltMicSelected = true; - } - else - ((OscilloscopeActivity) getActivity()).isInBuiltMicSelected = false; - } else { - ((OscilloscopeActivity) getActivity()).isAudioInputSelected = false; + ((OscilloscopeActivity) getActivity()).isInBuiltMicSelected = isChecked; + ((OscilloscopeActivity) getActivity()).isAudioInputSelected = isChecked; + ((OscilloscopeActivity) getActivity()).isMICSelected = !isChecked; + if (isChecked) { + pslabMicCheckBox.setChecked(false); + if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) { + requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, RECORD_AUDIO_REQUEST_CODE); + ((OscilloscopeActivity) getActivity()).isAudioInputSelected = false; + } } } }); + pslabMicCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + ((OscilloscopeActivity) getActivity()).isMICSelected = isChecked; + ((OscilloscopeActivity) getActivity()).isAudioInputSelected = isChecked; + ((OscilloscopeActivity) getActivity()).isInBuiltMicSelected = !isChecked; + if (isChecked) { + builtInMicCheckBox.setChecked(false); + if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) { + requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, RECORD_AUDIO_REQUEST_CODE); + ((OscilloscopeActivity) getActivity()).isAudioInputSelected = false; + } + } + } + }); return v; } @@ -298,8 +275,8 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis ((OscilloscopeActivity) getActivity()).isInBuiltMicSelected = true; } else { Toast.makeText(getActivity(), "This feature won't work.", Toast.LENGTH_SHORT).show(); - if (checkBoxMIC.isChecked()) - checkBoxMIC.toggle(); + if (builtInMicCheckBox.isChecked()) + builtInMicCheckBox.toggle(); } } } diff --git a/app/src/main/java/io/pslab/fragment/ESPFragment.java b/app/src/main/java/io/pslab/fragment/ESPFragment.java index 00ac88e71..255a22b7a 100644 --- a/app/src/main/java/io/pslab/fragment/ESPFragment.java +++ b/app/src/main/java/io/pslab/fragment/ESPFragment.java @@ -17,6 +17,7 @@ import java.io.IOException; import io.pslab.R; +import io.pslab.others.ScienceLabCommon; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; @@ -78,6 +79,10 @@ protected String doInBackground(Void... voids) { .url("http://" + espIPAddress) .build(); Response response = client.newCall(request).execute(); + if (response.code() == 200) { + ScienceLabCommon.setIsWifiConnected(true); + ScienceLabCommon.setEspBaseIP(espIPAddress); + } result = response.body().string(); } catch (IOException e) { e.printStackTrace(); diff --git a/app/src/main/java/io/pslab/fragment/FAQFragment.java b/app/src/main/java/io/pslab/fragment/FAQFragment.java index 176b26616..61b617b1a 100644 --- a/app/src/main/java/io/pslab/fragment/FAQFragment.java +++ b/app/src/main/java/io/pslab/fragment/FAQFragment.java @@ -2,6 +2,8 @@ import android.os.Bundle; import android.support.v4.app.Fragment; +import android.text.Html; +import android.text.method.LinkMovementMethod; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -23,15 +25,13 @@ public static FAQFragment newInstance() { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - questions = new String[]{getString(R.string.faq_question1), getString(R.string.faq_question2), getString(R.string.faq_question3), getString(R.string.faq_question4), getString(R.string.faq_question5)}; + questions = getResources().getStringArray(R.array.faq_questions); - answers = new String[][]{ - {getString(R.string.faq_answer1)}, - {getString(R.string.faq_answer2)}, - {getString(R.string.faq_answer3)}, - {getString(R.string.faq_answer4)}, - {getString(R.string.faq_answer5)} - }; + String[] ans = getResources().getStringArray(R.array.faq_answers); + answers = new String[ans.length][]; + for (int i = 0; i < ans.length; i++) { + answers[i] = new String[]{ans[i]}; + } } @Override @@ -114,7 +114,9 @@ public View getChildView(int questionPosition, final int childPosition, boolean holder = (ViewHolder) v.getTag(); } - holder.text.setText(getChild(questionPosition, childPosition).toString()); + holder.text.setClickable(true); + holder.text.setMovementMethod(LinkMovementMethod.getInstance()); + holder.text.setText(Html.fromHtml(getChild(questionPosition, childPosition).toString(), Html.FROM_HTML_MODE_COMPACT)); return v; } diff --git a/app/src/main/java/io/pslab/fragment/HomeFragment.java b/app/src/main/java/io/pslab/fragment/HomeFragment.java index 18a73cd53..150523361 100644 --- a/app/src/main/java/io/pslab/fragment/HomeFragment.java +++ b/app/src/main/java/io/pslab/fragment/HomeFragment.java @@ -12,20 +12,21 @@ import android.view.ViewGroup; import android.webkit.WebView; import android.webkit.WebViewClient; +import android.widget.Button; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.ScrollView; import android.widget.TextView; -import io.pslab.R; -import io.pslab.others.InitializationVariable; - import java.io.IOException; import butterknife.BindView; import butterknife.ButterKnife; import butterknife.Unbinder; +import io.pslab.R; +import io.pslab.others.InitializationVariable; +import io.pslab.others.ScienceLabCommon; import static io.pslab.others.ScienceLabCommon.scienceLab; @@ -55,6 +56,12 @@ public class HomeFragment extends Fragment { ProgressBar wvProgressBar; @BindView(R.id.steps_header_text) TextView stepsHeader; + @BindView(R.id.bluetooth_btn) + Button bluetoothButton; + @BindView(R.id.wifi_btn) + Button wifiButton; + @BindView(R.id.bluetooth_wifi_option_tv) + TextView bluetoothWifiOption; private boolean deviceFound = false, deviceConnected = false; private Unbinder unbinder; @@ -138,7 +145,32 @@ public boolean onKey(View v, int keyCode, KeyEvent event) { return false; } }); + if (ScienceLabCommon.scienceLab.isConnected()) { + bluetoothButton.setVisibility(View.GONE); + wifiButton.setVisibility(View.GONE); + bluetoothWifiOption.setVisibility(View.GONE); + } else { + bluetoothButton.setVisibility(View.VISIBLE); + wifiButton.setVisibility(View.VISIBLE); + bluetoothWifiOption.setVisibility(View.VISIBLE); + } + bluetoothButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + BluetoothScanFragment bluetoothScanFragment = new BluetoothScanFragment(); + bluetoothScanFragment.show(getActivity().getSupportFragmentManager(), "bluetooth"); + bluetoothScanFragment.setCancelable(true); + } + }); + wifiButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + ESPFragment espFragment = new ESPFragment(); + espFragment.show(getActivity().getSupportFragmentManager(), "wifi"); + espFragment.setCancelable(true); + } + }); return view; } diff --git a/app/src/main/java/io/pslab/fragment/LALogicLinesFragment.java b/app/src/main/java/io/pslab/fragment/LALogicLinesFragment.java index a59656ac5..e337bb149 100644 --- a/app/src/main/java/io/pslab/fragment/LALogicLinesFragment.java +++ b/app/src/main/java/io/pslab/fragment/LALogicLinesFragment.java @@ -21,7 +21,6 @@ import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; -import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.Spinner; @@ -106,10 +105,7 @@ public class LALogicLinesFragment extends Fragment { private ArrayList channelNames = new ArrayList<>(); private ArrayList edgesNames = new ArrayList<>(); private TextView tvTimeUnit, xCoordinateText; - private ImageView ledImageView; - private Runnable logicAnalysis; private Realm realm; - private ImageView recordButton; private GPSLogger gpsLogger; private CSVLogger csvLogger; private ArrayList recordXAxis; @@ -120,6 +116,7 @@ public class LALogicLinesFragment extends Fragment { private String csvHeader = "Timestamp,DateTime,Channel,ChannelMode,xData,yData,lat,lon"; private ArrayList channelSelectSpinners; private ArrayList edgeSelectSpinners; + private View rootView; public static LALogicLinesFragment newInstance(Activity activity) { LALogicLinesFragment laLogicLinesFragment = new LALogicLinesFragment(); @@ -140,112 +137,36 @@ public void onCreate(@Nullable Bundle savedInstanceState) { recordChannelMode = new ArrayList<>(); channelSelectSpinners = new ArrayList<>(); edgeSelectSpinners = new ArrayList<>(); - logicAnalysis = new Runnable() { - @Override - public void run() { - while (true) { - if (scienceLab.isConnected()) { - if (!String.valueOf(ledImageView.getTag()).equals("green")) { - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - ledImageView.setImageResource(R.drawable.green_led); - ledImageView.setTag("green"); - } - }); - } - } else { - if (!String.valueOf(ledImageView.getTag()).equals("red")) { - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - ledImageView.setImageResource(R.drawable.red_led); - ledImageView.setTag("red"); - } - }); - } - } - } - } - }; } @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - View v = inflater.inflate(R.layout.logic_analyzer_logic_lines, container, false); - // LED Indicator - ledImageView = v.findViewById(R.id.imageView_led_la); + rootView = inflater.inflate(R.layout.logic_analyzer_logic_lines, container, false); // Heading - tvTimeUnit = v.findViewById(R.id.la_tv_time_unit); + tvTimeUnit = rootView.findViewById(R.id.la_tv_time_unit); tvTimeUnit.setText(getString(R.string.time_unit_la)); - //recordButton - - recordButton = v.findViewById(R.id.la_record_button); - recordButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - long block = System.currentTimeMillis(); - double lat; - double lon; - if (gpsLogger.isGPSEnabled()) { - Location location = gpsLogger.getDeviceLocation(); - if (location != null) { - lat = location.getLatitude(); - lon = location.getLongitude(); - } else { - lat = 0.0; - lon = 0.0; - } - } else { - lat = 0.0; - lon = 0.0; - } - csvLogger.prepareLogFile(); - csvLogger.writeMetaData(getContext().getResources().getString(R.string.logical_analyzer)); - csvLogger.writeCSVFile(csvHeader); - recordSensorDataBlockID(new SensorDataBlock(block, getResources().getString(R.string.logical_analyzer))); - long timestamp = System.currentTimeMillis(); - String timeData = timestamp + "," + CSVLogger.FILE_NAME_FORMAT.format(new Date(timestamp)); - String locationData = lat + "," + lon; - for (int i = 0; i < recordXAxis.size(); i++) { - recordSensorData(new LogicAnalyzerData(timestamp + i, block, channels[i], recordChannelMode.get(i), recordXAxis.get(i), recordYAxis.get(i), lat, lon)); - String data = timeData + "," + channels[i] + "," + recordChannelMode.get(i) + "," + recordXAxis.get(i) + "," + recordYAxis.get(i) + "," + locationData; - csvLogger.writeCSVFile(data); - } - CustomSnackBar.showSnackBar(v, - getString(R.string.csv_store_text) + " " + csvLogger.getCurrentFilePath() - , getString(R.string.open), new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent intent = new Intent(getContext(), DataLoggerActivity.class); - intent.putExtra(DataLoggerActivity.CALLER_ACTIVITY, getResources().getString(R.string.logical_analyzer)); - startActivity(intent); - } - }, Snackbar.LENGTH_SHORT); - } - }); // Carousel View - carouselPicker = v.findViewById(R.id.carouselPicker); - llChannel1 = v.findViewById(R.id.ll_chart_channel_1); + carouselPicker = rootView.findViewById(R.id.carouselPicker); + llChannel1 = rootView.findViewById(R.id.ll_chart_channel_1); llChannel1.setVisibility(View.VISIBLE); - llChannel2 = v.findViewById(R.id.ll_chart_channel_2); + llChannel2 = rootView.findViewById(R.id.ll_chart_channel_2); llChannel2.setVisibility(View.GONE); - llChannel3 = v.findViewById(R.id.ll_chart_channel_3); + llChannel3 = rootView.findViewById(R.id.ll_chart_channel_3); llChannel3.setVisibility(View.GONE); - llChannel4 = v.findViewById(R.id.ll_chart_channel_4); + llChannel4 = rootView.findViewById(R.id.ll_chart_channel_4); llChannel4.setVisibility(View.GONE); - channelSelectSpinner1 = v.findViewById(R.id.channel_select_spinner_1); - channelSelectSpinner2 = v.findViewById(R.id.channel_select_spinner_2); - channelSelectSpinner3 = v.findViewById(R.id.channel_select_spinner_3); - channelSelectSpinner4 = v.findViewById(R.id.channel_select_spinner_4); - edgeSelectSpinner1 = v.findViewById(R.id.edge_select_spinner_1); - edgeSelectSpinner2 = v.findViewById(R.id.edge_select_spinner_2); - edgeSelectSpinner3 = v.findViewById(R.id.edge_select_spinner_3); - edgeSelectSpinner4 = v.findViewById(R.id.edge_select_spinner_4); - analyze_button = v.findViewById(R.id.analyze_button); + channelSelectSpinner1 = rootView.findViewById(R.id.channel_select_spinner_1); + channelSelectSpinner2 = rootView.findViewById(R.id.channel_select_spinner_2); + channelSelectSpinner3 = rootView.findViewById(R.id.channel_select_spinner_3); + channelSelectSpinner4 = rootView.findViewById(R.id.channel_select_spinner_4); + edgeSelectSpinner1 = rootView.findViewById(R.id.edge_select_spinner_1); + edgeSelectSpinner2 = rootView.findViewById(R.id.edge_select_spinner_2); + edgeSelectSpinner3 = rootView.findViewById(R.id.edge_select_spinner_3); + edgeSelectSpinner4 = rootView.findViewById(R.id.edge_select_spinner_4); + analyze_button = rootView.findViewById(R.id.analyze_button); channelMode = 1; channelSelectSpinners.add(channelSelectSpinner1); channelSelectSpinners.add(channelSelectSpinner2); @@ -262,9 +183,9 @@ public void onClick(View view) { channelMap.put(channels[2], 2); channelMap.put(channels[3], 3); // Axis Indicator - xCoordinateText = v.findViewById(R.id.x_coordinate_text); + xCoordinateText = rootView.findViewById(R.id.x_coordinate_text); xCoordinateText.setText("Time: 0.0 mS"); - progressBar = v.findViewById(R.id.la_progressBar); + progressBar = rootView.findViewById(R.id.la_progressBar); progressBar.setVisibility(View.GONE); ((LogicalAnalyzerActivity) getActivity()).setStatus(false); @@ -273,7 +194,7 @@ public void onClick(View view) { dataSets = new ArrayList<>(); // Creating base layout for chart - logicLinesChart = v.findViewById(R.id.chart_la); + logicLinesChart = rootView.findViewById(R.id.chart_la); logicLinesChart.setBorderWidth(2); Legend legend = logicLinesChart.getLegend(); legend.setTextColor(Color.WHITE); @@ -283,22 +204,62 @@ public void onClick(View view) { setCarouselPicker(); setAdapters(); - LogicalAnalyzerActivity laActivity = (LogicalAnalyzerActivity)getActivity(); + LogicalAnalyzerActivity laActivity = (LogicalAnalyzerActivity) getActivity(); if (laActivity.isPlayback) { setPlayBackData(laActivity.recordedLAData); } - return v; + return rootView; + } + + public void logData() { + long block = System.currentTimeMillis(); + double lat; + double lon; + if (gpsLogger.isGPSEnabled()) { + Location location = gpsLogger.getDeviceLocation(); + if (location != null) { + lat = location.getLatitude(); + lon = location.getLongitude(); + } else { + lat = 0.0; + lon = 0.0; + } + } else { + lat = 0.0; + lon = 0.0; + } + csvLogger.prepareLogFile(); + csvLogger.writeMetaData(getContext().getResources().getString(R.string.logical_analyzer)); + csvLogger.writeCSVFile(csvHeader); + recordSensorDataBlockID(new SensorDataBlock(block, getResources().getString(R.string.logical_analyzer))); + long timestamp = System.currentTimeMillis(); + String timeData = timestamp + "," + CSVLogger.FILE_NAME_FORMAT.format(new Date(timestamp)); + String locationData = lat + "," + lon; + for (int i = 0; i < recordXAxis.size(); i++) { + recordSensorData(new LogicAnalyzerData(timestamp + i, block, channels[i], recordChannelMode.get(i), recordXAxis.get(i), recordYAxis.get(i), lat, lon)); + String data = timeData + "," + channels[i] + "," + recordChannelMode.get(i) + "," + recordXAxis.get(i) + "," + recordYAxis.get(i) + "," + locationData; + csvLogger.writeCSVFile(data); + } + CustomSnackBar.showSnackBar(rootView, + getString(R.string.csv_store_text) + " " + csvLogger.getCurrentFilePath() + , getString(R.string.open), new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(getContext(), DataLoggerActivity.class); + intent.putExtra(DataLoggerActivity.CALLER_ACTIVITY, getResources().getString(R.string.logical_analyzer)); + startActivity(intent); + } + }, Snackbar.LENGTH_SHORT); } private void setPlayBackData(RealmResults data) { analyze_button.setVisibility(View.GONE); - recordButton.setVisibility(View.GONE); currentChannel = 0; setViewVisibility(data.size() - 1); channelNames.clear(); disableSpinners(); - carouselPicker.setCurrentItem(data.size() -1); - for (int i = 0; i < data.size(); i ++) { + carouselPicker.setCurrentItem(data.size() - 1); + for (int i = 0; i < data.size(); i++) { LogicAnalyzerData laData = data.get(i); channelNames.add(laData.getChannel()); edgeSelectSpinners.get(i).setSelection(laData.getChannelMode() - 1); @@ -308,7 +269,7 @@ private void setPlayBackData(RealmResults data) { int n = Math.min(xPoints.length, yPoints.length); double[] xaxis = new double[n]; double[] yaxis = new double[n]; - for (int j = 0; j < n; j ++) { + for (int j = 0; j < n; j++) { xaxis[j] = Double.valueOf(xPoints[j]); yaxis[j] = Double.valueOf(yPoints[j]); } @@ -329,7 +290,7 @@ private void setPlayBackData(RealmResults data) { singleChannelOtherEdges(xaxis, yaxis); break; } - currentChannel ++; + currentChannel++; } logicLinesChart.setData(new LineData(dataSets)); logicLinesChart.invalidate(); @@ -347,9 +308,6 @@ private void setPlayBackData(RealmResults data) { @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - if (scienceLab.isConnected()) { - new Thread(logicAnalysis).start(); - } carouselPicker.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override @@ -620,6 +578,7 @@ private void setViewVisibility(int mode) { break; } } + /** * Plots every edge of a digital pulse for one channel at a time * @@ -899,8 +858,6 @@ private void setCarouselPicker() { @Override public void onResume() { super.onResume(); - if (((AppCompatActivity) getActivity()).getSupportActionBar() != null) - ((AppCompatActivity) getActivity()).getSupportActionBar().hide(); } @Override diff --git a/app/src/main/java/io/pslab/fragment/OscilloscopePlaybackFragment.java b/app/src/main/java/io/pslab/fragment/OscilloscopePlaybackFragment.java index 1a95a12bc..cafe1b13b 100644 --- a/app/src/main/java/io/pslab/fragment/OscilloscopePlaybackFragment.java +++ b/app/src/main/java/io/pslab/fragment/OscilloscopePlaybackFragment.java @@ -19,8 +19,6 @@ public class OscilloscopePlaybackFragment extends Fragment { private OscilloscopeActivity oscilloscopeActivity; private TextView timebaseTextView; - private ImageView playButton; - private boolean isPlaying = false; public static OscilloscopePlaybackFragment newInstance() { return new OscilloscopePlaybackFragment(); @@ -31,24 +29,8 @@ public static OscilloscopePlaybackFragment newInstance() { public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_oscilloscope_playback, container, false); timebaseTextView = rootView.findViewById(R.id.timebase_data); - playButton = rootView.findViewById(R.id.play_button); CheckBox fourierCheckBox = rootView.findViewById(R.id.fourier_checkbox); - playButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (isPlaying) { - isPlaying = false; - playButton.setImageResource(R.drawable.ic_play_button); - oscilloscopeActivity.pauseData(); - } else { - isPlaying = true; - playButton.setImageResource(R.drawable.pause_icon); - oscilloscopeActivity.playRecordedData(); - } - } - }); - fourierCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { @@ -64,11 +46,6 @@ public void onCreate(@Nullable Bundle savedInstanceState) { oscilloscopeActivity = (OscilloscopeActivity) getActivity(); } - public void resetPlayButton() { - playButton.setImageResource(R.drawable.ic_play_button); - isPlaying = false; - } - public void setTimeBase(String timeBase) { timebaseTextView.setText(timeBase); } diff --git a/app/src/main/java/io/pslab/interfaces/HttpCallback.java b/app/src/main/java/io/pslab/interfaces/HttpCallback.java new file mode 100644 index 000000000..3bcdd62e8 --- /dev/null +++ b/app/src/main/java/io/pslab/interfaces/HttpCallback.java @@ -0,0 +1,6 @@ +package io.pslab.interfaces; + +public interface HttpCallback { + void success(T t1); + void error(Exception e); +} diff --git a/app/src/main/java/io/pslab/others/ScienceLabCommon.java b/app/src/main/java/io/pslab/others/ScienceLabCommon.java index bae5a80a3..8bd20b962 100644 --- a/app/src/main/java/io/pslab/others/ScienceLabCommon.java +++ b/app/src/main/java/io/pslab/others/ScienceLabCommon.java @@ -15,6 +15,8 @@ public class ScienceLabCommon { private static ScienceLabCommon scienceLabCommon = null; public static ScienceLab scienceLab; public boolean connected = false; + public static boolean isWifiConnected = false; + private static String espBaseIP = ""; private ScienceLabCommon() { } @@ -35,4 +37,20 @@ public static ScienceLabCommon getInstance() { } return scienceLabCommon; } + + public static String getEspIP() { + return espBaseIP; + } + + public static void setEspBaseIP(String espBaseIP) { + ScienceLabCommon.espBaseIP = espBaseIP; + } + + public static boolean isWifiConnected() { + return isWifiConnected; + } + + public static void setIsWifiConnected(boolean wifiConnected) { + isWifiConnected = wifiConnected; + } } diff --git a/app/src/main/res/drawable/btn_back_rounded.xml b/app/src/main/res/drawable/btn_back_rounded.xml index f3b6377f4..35e099f47 100644 --- a/app/src/main/res/drawable/btn_back_rounded.xml +++ b/app/src/main/res/drawable/btn_back_rounded.xml @@ -4,13 +4,13 @@ - + - + diff --git a/app/src/main/res/drawable/btn_back_rounded_light.xml b/app/src/main/res/drawable/btn_back_rounded_light.xml new file mode 100644 index 000000000..0965b8c5b --- /dev/null +++ b/app/src/main/res/drawable/btn_back_rounded_light.xml @@ -0,0 +1,6 @@ + + + + + diff --git a/app/src/main/res/drawable/ic_android_black_24dp.xml b/app/src/main/res/drawable/ic_android_black_24dp.xml new file mode 100644 index 000000000..401cbf63b --- /dev/null +++ b/app/src/main/res/drawable/ic_android_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_arrow_left_24dp.xml b/app/src/main/res/drawable/ic_arrow_left_24dp.xml new file mode 100644 index 000000000..b79d00f6e --- /dev/null +++ b/app/src/main/res/drawable/ic_arrow_left_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_arrow_right_24dp.xml b/app/src/main/res/drawable/ic_arrow_right_24dp.xml new file mode 100644 index 000000000..ff5a73fff --- /dev/null +++ b/app/src/main/res/drawable/ic_arrow_right_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_bluetooth.xml b/app/src/main/res/drawable/ic_bluetooth.xml deleted file mode 100644 index d1432adac..000000000 --- a/app/src/main/res/drawable/ic_bluetooth.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - diff --git a/app/src/main/res/drawable/ic_shopping_cart_black_24dp.xml b/app/src/main/res/drawable/ic_shopping_cart_black_24dp.xml new file mode 100644 index 000000000..11887e38f --- /dev/null +++ b/app/src/main/res/drawable/ic_shopping_cart_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_widgets_black_24dp.xml b/app/src/main/res/drawable/ic_widgets_black_24dp.xml new file mode 100644 index 000000000..4abb823f8 --- /dev/null +++ b/app/src/main/res/drawable/ic_widgets_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_wifi.xml b/app/src/main/res/drawable/ic_wifi.xml deleted file mode 100644 index aff45f329..000000000 --- a/app/src/main/res/drawable/ic_wifi.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - diff --git a/app/src/main/res/drawable/icon_version.xml b/app/src/main/res/drawable/icon_version.xml deleted file mode 100644 index 595985c9b..000000000 --- a/app/src/main/res/drawable/icon_version.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - diff --git a/app/src/main/res/layout-land/logic_analyzer_logic_lines.xml b/app/src/main/res/layout-land/logic_analyzer_logic_lines.xml index a371cd2ee..c6d03f7c6 100644 --- a/app/src/main/res/layout-land/logic_analyzer_logic_lines.xml +++ b/app/src/main/res/layout-land/logic_analyzer_logic_lines.xml @@ -36,13 +36,6 @@ android:textStyle="bold" android:layout_weight="1"/> - - - diff --git a/app/src/main/res/layout-sw600dp/fragment_channel_parameters.xml b/app/src/main/res/layout-sw600dp/fragment_channel_parameters.xml index 00bc2c7a8..0af5562de 100644 --- a/app/src/main/res/layout-sw600dp/fragment_channel_parameters.xml +++ b/app/src/main/res/layout-sw600dp/fragment_channel_parameters.xml @@ -1,7 +1,6 @@ @@ -10,11 +9,10 @@ android:id="@+id/checkBox_ch1_cp" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginLeft="16dp" - android:layout_marginStart="16dp" - android:layout_marginTop="16dp" + android:layout_marginStart="@dimen/osc_cb_margin2" + android:layout_marginTop="@dimen/osc_cb_margin2" android:text="@string/label_ch1" - android:textSize="18sp" + android:textSize="@dimen/osc_text_size_large" android:textStyle="normal|bold" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintTop_toTopOf="parent" /> @@ -23,11 +21,10 @@ android:id="@+id/checkBox_ch2_cp" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginBottom="16dp" - android:layout_marginLeft="16dp" - android:layout_marginStart="16dp" + android:layout_marginBottom="@dimen/osc_cb_margin2" + android:layout_marginStart="@dimen/osc_cb_margin2" android:text="@string/label_ch2" - android:textSize="18sp" + android:textSize="@dimen/osc_text_size_large" android:textStyle="normal|bold" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" /> @@ -36,70 +33,65 @@ android:id="@+id/checkBox_ch3_cp" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginEnd="16dp" - android:layout_marginRight="16dp" - android:layout_marginTop="16dp" + android:layout_marginEnd="@dimen/osc_cb_margin2" + android:layout_marginTop="@dimen/osc_cb_margin2" android:text="@string/ch3_value" - android:textSize="18sp" + android:textSize="@dimen/osc_text_size_large" android:textStyle="normal|bold" - app:layout_constraintRight_toRightOf="parent" + app:layout_constraintEnd_toStartOf="@id/mic_radio_group" + app:layout_constraintStart_toEndOf="@id/spinner_channel_select_cp" app:layout_constraintTop_toTopOf="parent" /> @@ -107,32 +99,47 @@ android:id="@+id/tv_ch2_cp" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginBottom="24dp" - android:layout_marginLeft="16dp" - android:layout_marginStart="16dp" + android:layout_marginBottom="@dimen/text_elevation" + android:layout_marginStart="@dimen/osc_cb_margin2" android:clickable="true" android:text="@string/label_ch2" android:textColor="@android:color/background_dark" - android:textSize="18sp" + android:textSize="@dimen/osc_text_size_large" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toRightOf="@+id/spinner_range_ch2_cp" /> - - - + android:layout_marginTop="@dimen/osc_cb_margin2" + android:layout_marginEnd="@dimen/osc_cb_margin2" + android:orientation="vertical" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent"> + + + \ No newline at end of file diff --git a/app/src/main/res/layout-v21/activity_wave_generator.xml b/app/src/main/res/layout-v21/activity_wave_generator.xml deleted file mode 100644 index 69626dd7e..000000000 --- a/app/src/main/res/layout-v21/activity_wave_generator.xml +++ /dev/null @@ -1,1050 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -