|
35 | 35 | import android.view.View; |
36 | 36 | import android.widget.AdapterView.AdapterContextMenuInfo; |
37 | 37 | import android.widget.CursorAdapter; |
| 38 | +import android.widget.ImageButton; |
38 | 39 | import android.widget.ListView; |
39 | 40 | import android.widget.TextView; |
40 | 41 | import android.widget.Toast; |
@@ -69,15 +70,28 @@ public class TrackManager extends ListActivity { |
69 | 70 | /** Track Identifier to export after request for write permission **/ |
70 | 71 | private long trackId = -1; |
71 | 72 |
|
| 73 | + private ImageButton btnNewTrack; |
| 74 | + |
72 | 75 | @Override |
73 | 76 | protected void onCreate(Bundle savedInstanceState) { |
74 | 77 | super.onCreate(savedInstanceState); |
75 | | - setContentView(R.layout.trackmanager); |
| 78 | + setContentView(R.layout.trackmanager); |
76 | 79 | getListView().setEmptyView(findViewById(R.id.trackmgr_empty)); |
77 | 80 | registerForContextMenu(getListView()); |
78 | 81 | if (savedInstanceState != null) { |
79 | 82 | prevItemVisible = savedInstanceState.getInt(PREV_VISIBLE, -1); |
80 | 83 | } |
| 84 | + //initialize the bottom start track |
| 85 | + btnNewTrack = (ImageButton) findViewById(R.id.trackmgr_hint_icon); |
| 86 | + //set a listener that makes the same functionality of (+) button in the main menu of this screen |
| 87 | + btnNewTrack.setOnClickListener(new View.OnClickListener() { |
| 88 | + @Override |
| 89 | + public void onClick(View v) { |
| 90 | + startTrackLogger(); |
| 91 | + //makes the button invisible when is an active track |
| 92 | + btnNewTrack.setVisibility(View.INVISIBLE); |
| 93 | + } |
| 94 | + }); |
81 | 95 | } |
82 | 96 |
|
83 | 97 | @Override |
@@ -109,6 +123,8 @@ protected void onResume() { |
109 | 123 | } |
110 | 124 | } |
111 | 125 | } else { |
| 126 | + //set the button to start a new track visible when there isn't an active track |
| 127 | + btnNewTrack.setVisibility(View.VISIBLE); |
112 | 128 | ((TextView) findViewById(R.id.trackmgr_hint)).setText(R.string.trackmgr_newtrack_hint); |
113 | 129 |
|
114 | 130 | // Scroll to the previous listview position, |
@@ -188,19 +204,7 @@ public boolean onPrepareOptionsMenu(Menu menu) { |
188 | 204 | public boolean onOptionsItemSelected(MenuItem item) { |
189 | 205 | switch (item.getItemId()) { |
190 | 206 | case R.id.trackmgr_menu_newtrack: |
191 | | - // Start track logger activity |
192 | | - try { |
193 | | - Intent i = new Intent(this, TrackLogger.class); |
194 | | - // New track |
195 | | - currentTrackId = createNewTrack(); |
196 | | - i.putExtra(TrackContentProvider.Schema.COL_TRACK_ID, currentTrackId); |
197 | | - startActivity(i); |
198 | | - } catch (CreateTrackException cte) { |
199 | | - Toast.makeText(this, |
200 | | - getResources().getString(R.string.trackmgr_newtrack_error).replace("{0}", cte.getMessage()), |
201 | | - Toast.LENGTH_LONG) |
202 | | - .show(); |
203 | | - } |
| 207 | + startTrackLogger(); |
204 | 208 | break; |
205 | 209 | case R.id.trackmgr_menu_continuetrack: |
206 | 210 | Intent i = new Intent(this, TrackLogger.class); |
@@ -265,6 +269,25 @@ public void onClick(DialogInterface dialog, int which) { |
265 | 269 | return super.onOptionsItemSelected(item); |
266 | 270 | } |
267 | 271 |
|
| 272 | + /** |
| 273 | + * This method prepare the new track and set an id, then start a new TrackLogger with the new track id |
| 274 | + */ |
| 275 | + private void startTrackLogger(){ |
| 276 | + // Start track logger activity |
| 277 | + try { |
| 278 | + Intent i = new Intent(this, TrackLogger.class); |
| 279 | + // New track |
| 280 | + currentTrackId = createNewTrack(); |
| 281 | + i.putExtra(TrackContentProvider.Schema.COL_TRACK_ID, currentTrackId); |
| 282 | + startActivity(i); |
| 283 | + } catch (CreateTrackException cte) { |
| 284 | + Toast.makeText(this, |
| 285 | + getResources().getString(R.string.trackmgr_newtrack_error).replace("{0}", cte.getMessage()), |
| 286 | + Toast.LENGTH_LONG) |
| 287 | + .show(); |
| 288 | + } |
| 289 | + } |
| 290 | + |
268 | 291 |
|
269 | 292 | private void requestPermissionAndExport(int typeCode){ |
270 | 293 | if (ContextCompat.checkSelfPermission(this, |
|
0 commit comments