Skip to content

Commit c4f43cc

Browse files
neel1998makoteq
authored andcommitted
wave generator ui changed (fossasia#1943)
1 parent c20fceb commit c4f43cc

14 files changed

+1216
-2124
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
android:screenOrientation="portrait" />
8585
<activity
8686
android:name=".activity.WaveGeneratorActivity"
87-
android:screenOrientation="userLandscape" />
87+
android:screenOrientation="portrait" />
8888
<activity
8989
android:name=".activity.AccelerometerActivity"
9090
android:screenOrientation="portrait" />

app/src/main/java/io/pslab/activity/WaveGeneratorActivity.java

Lines changed: 109 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.content.DialogInterface;
66
import android.content.Intent;
77
import android.content.SharedPreferences;
8+
import android.graphics.Color;
89
import android.graphics.drawable.Drawable;
910
import android.location.Location;
1011
import android.location.LocationManager;
@@ -23,6 +24,8 @@
2324
import android.util.Log;
2425
import android.view.GestureDetector;
2526
import android.view.LayoutInflater;
27+
import android.view.Menu;
28+
import android.view.MenuItem;
2629
import android.view.MotionEvent;
2730
import android.view.View;
2831
import android.view.Window;
@@ -34,7 +37,9 @@
3437
import android.widget.RelativeLayout;
3538
import android.widget.TextView;
3639
import android.widget.Toast;
40+
import android.support.v7.widget.Toolbar;
3741

42+
import com.github.mikephil.charting.charts.LineChart;
3843
import com.warkiz.widget.IndicatorSeekBar;
3944

4045
import java.util.Date;
@@ -150,8 +155,6 @@ public class WaveGeneratorActivity extends AppCompatActivity {
150155
ImageButton imgBtnDown;
151156
@BindView(R.id.seek_bar_wave_gen)
152157
IndicatorSeekBar seekBar;
153-
@BindView(R.id.btn_view)
154-
Button btnView;
155158
//bottomSheet
156159
@BindView(R.id.bottom_sheet)
157160
LinearLayout bottomSheet;
@@ -161,10 +164,10 @@ public class WaveGeneratorActivity extends AppCompatActivity {
161164
ImageView arrowUpDown;
162165
@BindView(R.id.sheet_slide_text)
163166
TextView bottomSheetSlideText;
164-
@BindView(R.id.show_guide_wave_generator)
165-
TextView showText;
166167
@BindView(R.id.wave_phase)
167168
TextView wavePhaseTitle;
169+
@BindView(R.id.btn_produce_sound)
170+
Button btnProduceSound;
168171
ScienceLab scienceLab;
169172
BottomSheetBehavior bottomSheetBehavior;
170173
GestureDetector gestureDetector;
@@ -173,7 +176,6 @@ public class WaveGeneratorActivity extends AppCompatActivity {
173176
private Timer waveGenCounter;
174177
private Handler wavegenHandler = new Handler();
175178
private AlertDialog waveDialog;
176-
private boolean btnLongpressed;
177179
private CSVLogger csvLogger;
178180
private WaveConst waveBtnActive, pwmBtnActive, prop_active, digital_mode;
179181
private TextView activePropTv = null;
@@ -186,6 +188,7 @@ public class WaveGeneratorActivity extends AppCompatActivity {
186188
private ConstraintLayout squareModeLayout;
187189
private RelativeLayout pwmModeControls;
188190
private RelativeLayout squareModeControls;
191+
private LineChart previewChart;
189192

190193
@SuppressLint("ClickableViewAccessibility")
191194
@Override
@@ -202,10 +205,17 @@ protected void onCreate(Bundle savedInstanceState) {
202205
gpsLogger = new GPSLogger(this,
203206
(LocationManager) getSystemService(Context.LOCATION_SERVICE));
204207

205-
208+
Toolbar toolbar = findViewById(R.id.toolbar);
209+
setSupportActionBar(toolbar);
210+
getSupportActionBar().setTitle(getString(R.string.wave_generator));
211+
if (getSupportActionBar() != null) {
212+
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
213+
getSupportActionBar().setDisplayShowHomeEnabled(true);
214+
}
206215
coordinatorLayout = findViewById(R.id.wave_generator_coordinator_layout);
207216
squareModeLayout = findViewById(R.id.square_mode_layout);
208217
pwmModeLayout = findViewById(R.id.pwm_mode_layout);
218+
previewChart = findViewById(R.id.chart_preview);
209219

210220
squareModeControls = findViewById(R.id.square_mode_controls);
211221
pwmModeControls = findViewById(R.id.pwm_mode_controls);
@@ -417,49 +427,6 @@ public void onClick(View view) {
417427

418428
monitorLongClicks(imgBtnUp, imgBtnDown);
419429

420-
btnView.setOnClickListener(new View.OnClickListener() {
421-
@Override
422-
public void onClick(View view) {
423-
double freq1 = (double) (WaveGeneratorCommon.wave.get(WaveConst.WAVE1).get(WaveConst.FREQUENCY));
424-
double freq2 = (double) WaveGeneratorCommon.wave.get(WaveConst.WAVE2).get(WaveConst.FREQUENCY);
425-
double phase = (double) WaveGeneratorCommon.wave.get(WaveConst.WAVE2).get(WaveConst.PHASE);
426-
427-
String waveType1 = WaveGeneratorCommon.wave.get(WaveConst.WAVE1).get(WaveConst.WAVETYPE) == SIN ? "sine" : "tria";
428-
String waveType2 = WaveGeneratorCommon.wave.get(WaveConst.WAVE2).get(WaveConst.WAVETYPE) == SIN ? "sine" : "tria";
429-
430-
if (scienceLab.isConnected()) {
431-
if (digital_mode == WaveConst.SQUARE) {
432-
if (phase == WaveData.PHASE_MIN.getValue()) {
433-
scienceLab.setW1(freq1, waveType1);
434-
scienceLab.setW2(freq2, waveType2);
435-
} else {
436-
scienceLab.setWaves(freq1, phase, freq2);
437-
}
438-
} else {
439-
double freqSqr1 = (double) WaveGeneratorCommon.wave.get(WaveConst.SQR1).get(WaveConst.FREQUENCY);
440-
double dutySqr1 = (double) WaveGeneratorCommon.wave.get(WaveConst.SQR1).get(WaveConst.DUTY) / 100;
441-
double dutySqr2 = ((double) WaveGeneratorCommon.wave.get(WaveConst.SQR2).get(WaveConst.DUTY)) / 100;
442-
double phaseSqr2 = (double) WaveGeneratorCommon.wave.get(WaveConst.SQR2).get(WaveConst.PHASE) / 360;
443-
double dutySqr3 = ((double) WaveGeneratorCommon.wave.get(WaveConst.SQR3).get(WaveConst.DUTY)) / 100;
444-
double phaseSqr3 = (double) WaveGeneratorCommon.wave.get(WaveConst.SQR3).get(WaveConst.PHASE) / 360;
445-
double dutySqr4 = ((double) WaveGeneratorCommon.wave.get(WaveConst.SQR4).get(WaveConst.DUTY)) / 100;
446-
double phaseSqr4 = (double) WaveGeneratorCommon.wave.get(WaveConst.SQR4).get(WaveConst.PHASE) / 360;
447-
448-
scienceLab.sqrPWM(freqSqr1, dutySqr1, phaseSqr2, dutySqr2, phaseSqr3, dutySqr3, phaseSqr4, dutySqr4, false);
449-
}
450-
451-
waveDialog.show();
452-
Window window = waveDialog.getWindow();
453-
window.setLayout(dpToPx(350), dpToPx(300));
454-
waveDialog.getButton(DialogInterface.BUTTON_NEGATIVE)
455-
.setTextColor(ContextCompat.getColor(WaveGeneratorActivity.this, R.color.colorPrimary));
456-
457-
} else {
458-
Toast.makeText(WaveGeneratorActivity.this, R.string.device_not_connected, Toast.LENGTH_SHORT).show();
459-
}
460-
}
461-
});
462-
463430
seekBar.setOnSeekChangeListener(new IndicatorSeekBar.OnSeekBarChangeListener() {
464431
@Override
465432
public void onProgressChanged(IndicatorSeekBar seekBar, int progress, float progressFloat, boolean fromUserTouch) {
@@ -488,44 +455,15 @@ public void onStopTrackingTouch(IndicatorSeekBar seekBar) {
488455
}
489456
});
490457

491-
ImageView guideImageView = findViewById(R.id.wave_generator_guide_button);
492-
guideImageView.setOnClickListener(new View.OnClickListener() {
493-
@Override
494-
public void onClick(View v) {
495-
bottomSheetBehavior.setState(bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN ?
496-
BottomSheetBehavior.STATE_EXPANDED : BottomSheetBehavior.STATE_HIDDEN);
497-
}
498-
});
499-
guideImageView.setOnLongClickListener(new View.OnLongClickListener() {
500-
@Override
501-
public boolean onLongClick(View v) {
502-
showText.setVisibility(View.VISIBLE);
503-
btnLongpressed = true;
504-
return true;
505-
}
506-
});
507-
guideImageView.setOnTouchListener(new View.OnTouchListener() {
508-
@Override
509-
public boolean onTouch(View v, MotionEvent event) {
510-
v.onTouchEvent(event);
511-
if (event.getAction() == MotionEvent.ACTION_UP) {
512-
if (btnLongpressed) {
513-
showText.setVisibility(View.GONE);
514-
btnLongpressed = false;
515-
}
516-
}
517-
return true;
518-
}
519-
});
520-
521458
if (getIntent().getExtras() != null && getIntent().getExtras().getBoolean(KEY_LOG)) {
522459
recordedWaveData = LocalDataLog.with()
523460
.getBlockOfWaveRecords(getIntent().getExtras().getLong(DATA_BLOCK));
524461
setReceivedData();
525462
}
463+
chartInit();
526464
}
527465

528-
public void saveWaveConfig(View view) {
466+
public void saveWaveConfig() {
529467
long block = System.currentTimeMillis();
530468
csvLogger.prepareLogFile();
531469
csvLogger.writeMetaData(getResources().getString(R.string.wave_generator));
@@ -649,6 +587,79 @@ public void setReceivedData() {
649587
}
650588
}
651589

590+
private void viewWave() {
591+
double freq1 = (double) (WaveGeneratorCommon.wave.get(WaveConst.WAVE1).get(WaveConst.FREQUENCY));
592+
double freq2 = (double) WaveGeneratorCommon.wave.get(WaveConst.WAVE2).get(WaveConst.FREQUENCY);
593+
double phase = (double) WaveGeneratorCommon.wave.get(WaveConst.WAVE2).get(WaveConst.PHASE);
594+
595+
String waveType1 = WaveGeneratorCommon.wave.get(WaveConst.WAVE1).get(WaveConst.WAVETYPE) == SIN ? "sine" : "tria";
596+
String waveType2 = WaveGeneratorCommon.wave.get(WaveConst.WAVE2).get(WaveConst.WAVETYPE) == SIN ? "sine" : "tria";
597+
598+
if (scienceLab.isConnected()) {
599+
if (digital_mode == WaveConst.SQUARE) {
600+
if (phase == WaveData.PHASE_MIN.getValue()) {
601+
scienceLab.setW1(freq1, waveType1);
602+
scienceLab.setW2(freq2, waveType2);
603+
} else {
604+
scienceLab.setWaves(freq1, phase, freq2);
605+
}
606+
} else {
607+
double freqSqr1 = (double) WaveGeneratorCommon.wave.get(WaveConst.SQR1).get(WaveConst.FREQUENCY);
608+
double dutySqr1 = (double) WaveGeneratorCommon.wave.get(WaveConst.SQR1).get(WaveConst.DUTY) / 100;
609+
double dutySqr2 = ((double) WaveGeneratorCommon.wave.get(WaveConst.SQR2).get(WaveConst.DUTY)) / 100;
610+
double phaseSqr2 = (double) WaveGeneratorCommon.wave.get(WaveConst.SQR2).get(WaveConst.PHASE) / 360;
611+
double dutySqr3 = ((double) WaveGeneratorCommon.wave.get(WaveConst.SQR3).get(WaveConst.DUTY)) / 100;
612+
double phaseSqr3 = (double) WaveGeneratorCommon.wave.get(WaveConst.SQR3).get(WaveConst.PHASE) / 360;
613+
double dutySqr4 = ((double) WaveGeneratorCommon.wave.get(WaveConst.SQR4).get(WaveConst.DUTY)) / 100;
614+
double phaseSqr4 = (double) WaveGeneratorCommon.wave.get(WaveConst.SQR4).get(WaveConst.PHASE) / 360;
615+
616+
scienceLab.sqrPWM(freqSqr1, dutySqr1, phaseSqr2, dutySqr2, phaseSqr3, dutySqr3, phaseSqr4, dutySqr4, false);
617+
}
618+
619+
waveDialog.show();
620+
Window window = waveDialog.getWindow();
621+
window.setLayout(dpToPx(350), dpToPx(300));
622+
waveDialog.getButton(DialogInterface.BUTTON_NEGATIVE)
623+
.setTextColor(ContextCompat.getColor(WaveGeneratorActivity.this, R.color.colorPrimary));
624+
625+
} else {
626+
Toast.makeText(WaveGeneratorActivity.this, R.string.device_not_connected, Toast.LENGTH_SHORT).show();
627+
}
628+
}
629+
630+
@Override
631+
public boolean onCreateOptionsMenu(Menu menu) {
632+
getMenuInflater().inflate(R.menu.wave_generator_menu, menu);
633+
return true;
634+
}
635+
636+
@Override
637+
public boolean onOptionsItemSelected(MenuItem item) {
638+
switch (item.getItemId()) {
639+
case android.R.id.home:
640+
finish();
641+
break;
642+
case R.id.save_data:
643+
saveWaveConfig();
644+
break;
645+
case R.id.play_data:
646+
viewWave();
647+
break;
648+
case R.id.show_guide:
649+
bottomSheetBehavior.setState(bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN ?
650+
BottomSheetBehavior.STATE_EXPANDED : BottomSheetBehavior.STATE_HIDDEN);
651+
break;
652+
case R.id.show_logged_data:
653+
Intent intent = new Intent(WaveGeneratorActivity.this, DataLoggerActivity.class);
654+
intent.putExtra(DataLoggerActivity.CALLER_ACTIVITY, getString(R.string.wave_generator));
655+
startActivity(intent);
656+
break;
657+
default:
658+
break;
659+
}
660+
return true;
661+
}
662+
652663
@Override
653664
protected void onResume() {
654665
super.onResume();
@@ -918,7 +929,25 @@ private void setValue() {
918929
Double dValue = (double) value;
919930
String valueText = DataFormatter.formatDouble(dValue, DataFormatter.MEDIUM_PRECISION_FORMAT) + " " + unit;
920931
activePropTv.setText(valueText);
932+
}
921933

934+
private void chartInit() {
935+
previewChart.setTouchEnabled(true);
936+
previewChart.setHighlightPerDragEnabled(true);
937+
previewChart.setDragEnabled(true);
938+
previewChart.setScaleEnabled(true);
939+
previewChart.setDrawGridBackground(false);
940+
previewChart.setPinchZoom(true);
941+
previewChart.setScaleYEnabled(false);
942+
previewChart.setBackgroundColor(Color.BLACK);
943+
previewChart.getDescription().setEnabled(false);
944+
previewChart.getXAxis().setAxisMaximum(1000);
945+
previewChart.getXAxis().setAxisMinimum(0);
946+
previewChart.getXAxis().setTextColor(Color.WHITE);
947+
previewChart.getAxisLeft().setAxisMaximum(5);
948+
previewChart.getAxisLeft().setAxisMinimum(-5);
949+
previewChart.fitScreen();
950+
previewChart.invalidate();
922951
}
923952

924953
private void toggleSeekBtns(boolean state) {

0 commit comments

Comments
 (0)