44import android .annotation .TargetApi ;
55import android .app .Activity ;
66import android .support .annotation .NonNull ;
7+ import android .support .design .widget .CoordinatorLayout ;
78import android .support .design .widget .Snackbar ;
89import android .support .design .widget .TabLayout ;
910import android .support .v7 .app .AlertDialog ;
2829import android .text .Editable ;
2930import android .text .TextWatcher ;
3031import android .util .Log ;
32+ import android .view .Gravity ;
3133import android .view .LayoutInflater ;
3234import android .view .View ;
3335import android .view .View .OnClickListener ;
@@ -106,11 +108,14 @@ public class ReportFragment extends Fragment {
106108 private String source ;
107109 private LinearLayoutCompat btnPhoto ;
108110 private LinearLayoutCompat layoutPhoto ;
111+ private LinearLayoutCompat btnSound ;
112+ private LinearLayoutCompat layoutSound ;
109113 private ViewSwitcher photoviewSwitcher ;
110114 public static final int CAMERA_REQUEST = 101 ;
111115 public static final int LOCATION_REQUEST = 102 ;
112116 public static final int GALLERY_REQUEST = 103 ;
113117 public static final int READ_STORAGE_REQUEST = 104 ;
118+ public static final int RECORDER_REQUEST = 104 ;
114119
115120 private static final boolean ATTRIBUTES_ENABLED = false ;
116121
@@ -130,8 +135,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle st
130135
131136 btnPhoto = (LinearLayoutCompat ) view .findViewById (R .id .photoButton );
132137 layoutPhoto = (LinearLayoutCompat ) view .findViewById (R .id .photoLayout );
138+ btnSound = (LinearLayoutCompat ) view .findViewById (R .id .soundButton );
139+ layoutSound = (LinearLayoutCompat ) view .findViewById (R .id .soundLayout );
133140 LinearLayoutCompat btnService = (LinearLayoutCompat ) view .findViewById (R .id .serviceButton );
134141 LinearLayoutCompat btnLocation = (LinearLayoutCompat ) view .findViewById (R .id .locationButton );
142+
135143 View descriptionView = view .findViewById (R .id .report_description_textbox );
136144 FloatingActionButton btnSubmit = (FloatingActionButton ) view .findViewById (R .id .report_submit );
137145 photoviewSwitcher = (ViewSwitcher ) view .findViewById (R .id .report_photoviewswitcher );
@@ -168,7 +176,20 @@ public void onClick(View v) {
168176 onPhotoButtonClicked ();
169177 }
170178 });
171-
179+ btnSound .setOnClickListener (new OnClickListener () {
180+ @ Override
181+ public void onClick (View v ) {
182+ hideKeyBoard (v );
183+ onSoundButtonClicked ();
184+ }
185+ });
186+ layoutSound .setOnClickListener (new OnClickListener () {
187+ @ Override
188+ public void onClick (View v ) {
189+ hideKeyBoard (v );
190+ onSoundButtonClicked ();
191+ }
192+ });
172193 btnLocation .setOnClickListener (new OnClickListener () {
173194 @ Override
174195 public void onClick (View v ) {
@@ -430,15 +451,31 @@ private boolean validate(View v) {
430451
431452 }
432453 if (!isValid ) {
433- String result = getString (R .string .failure_posting_service );
434- Snackbar .make (v , result , Snackbar .LENGTH_SHORT )
435- .show ();
454+ hideFab ();
455+ // String result = getString(R.string.failure_posting_service);
456+ // Snackbar.make(v, result, Snackbar.LENGTH_SHORT)
457+ // .show();
458+ } else {
459+ showFab ();
436460 }
437461
438-
439462 return isValid ;
440463 }
441464
465+ private void showFab () {
466+ CoordinatorLayout .LayoutParams p = new CoordinatorLayout .LayoutParams (CoordinatorLayout .LayoutParams .WRAP_CONTENT , CoordinatorLayout .LayoutParams .WRAP_CONTENT );
467+ View fab = getActivity ().findViewById (R .id .report_submit );
468+ p .anchorGravity = Gravity .BOTTOM | Gravity .END ;
469+ p .setAnchorId (R .id .appbar );
470+ fab .setLayoutParams (p );
471+ fab .setVisibility (View .VISIBLE );
472+ }
473+
474+ private void hideFab () {
475+ View fab = getActivity ().findViewById (R .id .report_submit );
476+ fab .setVisibility (View .GONE );
477+ }
478+
442479 private Boolean checkAnonymous () {
443480 SharedPreferences settings = getActivity ().getPreferences (Context .MODE_PRIVATE );
444481 String email = settings .getString ("email" , null );
@@ -539,7 +576,7 @@ private void onServiceButtonClicked() {
539576 values [index ] = item .getServiceName ();
540577 index ++;
541578 }
542- builder .setTitle (R .string .report_service ).setItems (values , new DialogInterface .OnClickListener () {
579+ builder .setTitle (R .string .report_hint_service ).setItems (values , new DialogInterface .OnClickListener () {
543580 public void onClick (DialogInterface dialog , int index ) {
544581 serviceName = values [index ];
545582 serviceCode = codes [index ];
@@ -600,7 +637,13 @@ public void onClick(DialogInterface dialog, int id) {
600637 builder .show ();
601638
602639 }
640+ /**
641+ * User clicked the Button to add a sound to the request.
642+ * We present the user with a dialog to select a sound from storage, or use the recorder.
643+ */
644+ private void onSoundButtonClicked () {
603645
646+ }
604647 private void onLocationButtonClicked () {
605648 if (ContextCompat .checkSelfPermission (getContext (), Manifest .permission_group .LOCATION ) == PackageManager .PERMISSION_DENIED ) {
606649 requestPermissions (new String []{Manifest .permission .ACCESS_COARSE_LOCATION ,
0 commit comments