11package io .pslab .activity ;
22
3+ import android .content .Intent ;
34import android .content .SharedPreferences ;
45import android .os .Build ;
56import android .os .Bundle ;
1011import android .support .v7 .app .AppCompatActivity ;
1112import android .support .v7 .widget .Toolbar ;
1213import android .view .GestureDetector ;
14+ import android .view .Menu ;
1315import android .view .MenuItem ;
1416import android .view .MotionEvent ;
1517import android .view .View ;
2022import android .widget .TextView ;
2123
2224import io .pslab .R ;
23- import io .pslab .communication .ScienceLab ;
2425import io .pslab .fragment .LALogicLinesFragment ;
2526import io .pslab .models .LogicAnalyzerData ;
2627import io .pslab .others .LocalDataLog ;
2728import io .pslab .others .MathUtils ;
28- import io .pslab .others .ScienceLabCommon ;
2929
30- import butterknife .BindView ;
31- import butterknife .ButterKnife ;
3230import io .pslab .others .SwipeGestureDetector ;
3331import io .realm .RealmResults ;
3432
@@ -40,9 +38,6 @@ public class LogicalAnalyzerActivity extends AppCompatActivity {
4038
4139 public static final String PREFS_NAME = "LogicAnalyzerPreference" ;
4240
43- @ BindView (R .id .logical_analyzer_toolbar )
44- Toolbar toolbar ;
45- private ScienceLab scienceLab ;
4641 private boolean isRunning = false ;
4742
4843 //Bottom Sheet
@@ -56,22 +51,18 @@ public class LogicalAnalyzerActivity extends AppCompatActivity {
5651 private TextView bottomSheetDesc ;
5752 private BottomSheetBehavior bottomSheetBehavior ;
5853 private GestureDetector gestureDetector ;
59- private TextView showText ;
60- private boolean btnLongpressed ;
6154 private final String KEY_LOG = "has_log" ;
6255 private final String DATA_BLOCK = "data_block" ;
6356 public boolean isPlayback = false ;
6457 public RealmResults <LogicAnalyzerData > recordedLAData ;
65-
58+ private LALogicLinesFragment laLogicLinesFragment ;
6659
6760 @ Override
6861 protected void onCreate (@ Nullable Bundle savedInstanceState ) {
6962 super .onCreate (savedInstanceState );
7063 requestWindowFeature (Window .FEATURE_NO_TITLE );
7164 getWindow ().setFlags (WindowManager .LayoutParams .FLAG_FULLSCREEN ,WindowManager .LayoutParams .FLAG_FULLSCREEN );
7265 setContentView (R .layout .activity_logic_analyzer );
73- scienceLab = ScienceLabCommon .scienceLab ;
74- ButterKnife .bind (this );
7566
7667 // Bottom Sheet guide
7768 bottomSheet = findViewById (R .id .bottom_sheet );
@@ -82,7 +73,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
8273 bottomSheetText = findViewById (R .id .custom_dialog_text );
8374 bottomSheetSchematic = findViewById (R .id .custom_dialog_schematic );
8475 bottomSheetDesc = findViewById (R .id .custom_dialog_desc );
85- showText = findViewById (R .id .show_guide_logic_analyzer );
8676 // Inflating bottom sheet dialog on how to use Logic Analyzer
8777 setUpBottomSheet ();
8878 tvShadow .setOnClickListener (new View .OnClickListener () {
@@ -96,42 +86,16 @@ public void onClick(View v) {
9686
9787 removeStatusBar ();
9888
99- getSupportFragmentManager ().beginTransaction ().add (R .id .la_frame_layout , LALogicLinesFragment .newInstance (this )).commit ();
89+ laLogicLinesFragment = LALogicLinesFragment .newInstance (this );
90+ getSupportFragmentManager ().beginTransaction ().add (R .id .la_frame_layout , laLogicLinesFragment ).commit ();
91+ Toolbar toolbar = findViewById (R .id .toolbar );
10092 setSupportActionBar (toolbar );
93+ getSupportActionBar ().setTitle (R .string .logical_analyzer );
10194 if (getSupportActionBar () != null ) {
10295 getSupportActionBar ().setDisplayHomeAsUpEnabled (true );
96+ getSupportActionBar ().setDisplayShowHomeEnabled (true );
10397 }
10498
105- ImageView guideImageView = findViewById (R .id .logic_analyzer_guide_button );
106- guideImageView .setOnClickListener (new View .OnClickListener () {
107- @ Override
108- public void onClick (View v ) {
109- bottomSheetBehavior .setState (bottomSheetBehavior .getState () == BottomSheetBehavior .STATE_HIDDEN ?
110- BottomSheetBehavior .STATE_EXPANDED : BottomSheetBehavior .STATE_HIDDEN );
111- }
112- });
113- guideImageView .setOnLongClickListener (new View .OnLongClickListener () {
114- @ Override
115- public boolean onLongClick (View v ) {
116- showText .setVisibility (View .VISIBLE );
117- btnLongpressed = true ;
118- return true ;
119- }
120- });
121- guideImageView .setOnTouchListener (new View .OnTouchListener () {
122- @ Override
123- public boolean onTouch (View v , MotionEvent event ) {
124- v .onTouchEvent (event );
125- if (event .getAction ()==MotionEvent .ACTION_UP ){
126- if (btnLongpressed ){
127- showText .setVisibility (View .GONE );
128- btnLongpressed = false ;
129- }
130- }
131- return true ;
132- }
133- });
134-
13599 if (getIntent ().getExtras () != null && getIntent ().getExtras ().getBoolean (KEY_LOG )) {
136100 recordedLAData = LocalDataLog .with ()
137101 .getBlockOfLARecords (getIntent ().getExtras ().getLong (DATA_BLOCK ));
@@ -161,16 +125,35 @@ private void removeStatusBar() {
161125 | View .SYSTEM_UI_FLAG_IMMERSIVE_STICKY ));
162126 }
163127 }
128+
129+ @ Override
130+ public boolean onCreateOptionsMenu (Menu menu ) {
131+ getMenuInflater ().inflate (R .menu .logical_analyzer_menu , menu );
132+ return true ;
133+ }
134+
164135 @ Override
165136 public boolean onOptionsItemSelected (MenuItem item ) {
166- int id = item .getItemId ();
167- if (id == android .R .id .home ) {
168- onBackPressed ();
169- return true ;
137+ switch (item .getItemId ()) {
138+ case android .R .id .home :
139+ finish ();
140+ break ;
141+ case R .id .show_logged_data :
142+ Intent intent = new Intent (LogicalAnalyzerActivity .this , DataLoggerActivity .class );
143+ intent .putExtra (DataLoggerActivity .CALLER_ACTIVITY , getResources ().getString (R .string .logical_analyzer ));
144+ startActivity (intent );
145+ break ;
146+ case R .id .save_graph :
147+ laLogicLinesFragment .logData ();
148+ break ;
149+ case R .id .show_guide :
150+ bottomSheetBehavior .setState (BottomSheetBehavior .STATE_EXPANDED );
151+ break ;
152+ default :
153+ break ;
170154 }
171- return super . onOptionsItemSelected ( item ) ;
155+ return true ;
172156 }
173-
174157 @ Override
175158 public void onBackPressed () {
176159 if (!isRunning )
0 commit comments