Skip to content

Commit 7a20387

Browse files
Implementing sound recorder
1 parent 1a0f1dd commit 7a20387

12 files changed

Lines changed: 198 additions & 66 deletions

File tree

app/src/main/java/org/open311/android/MainActivity.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
import android.view.MenuItem;
1616
import android.view.View;
1717

18-
import com.mapbox.mapboxsdk.MapboxAccountManager;
19-
2018
import org.codeforamerica.open311.facade.APIWrapper;
2119
import org.codeforamerica.open311.facade.APIWrapperFactory;
2220
import org.codeforamerica.open311.facade.EndpointType;
@@ -84,10 +82,6 @@ protected void onCreate(Bundle savedInstanceState) {
8482
installationId = Installation.id(this);
8583
setContentView(R.layout.activity_main);
8684

87-
// Mapbox access token only needs to be configured once in your app
88-
MapboxAccountManager.start(this, getString(R.string.mapbox_api_key));
89-
90-
9185
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
9286
setSupportActionBar(toolbar);
9387
getSupportFragmentManager().addOnBackStackChangedListener(this);

app/src/main/java/org/open311/android/MapActivity.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import android.support.design.widget.FloatingActionButton;
2929

30+
import com.mapbox.mapboxsdk.MapboxAccountManager;
3031
import com.mapbox.mapboxsdk.annotations.MarkerViewOptions;
3132
import com.mapbox.mapboxsdk.camera.CameraPosition;
3233
import com.mapbox.mapboxsdk.geometry.LatLng;
@@ -81,6 +82,8 @@ private enum source {
8182
protected void onCreate(Bundle savedInstanceState) {
8283

8384
super.onCreate(savedInstanceState);
85+
// Mapbox access token only needs to be configured once in your app
86+
MapboxAccountManager.start(this, getString(R.string.mapbox_api_key));
8487
setContentView(R.layout.activity_map);
8588
locationServices = LocationServices.getLocationServices(MapActivity.this);
8689
context = this;

app/src/main/java/org/open311/android/fragments/ReportFragment.java

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.annotation.TargetApi;
55
import android.app.Activity;
66
import android.support.annotation.NonNull;
7+
import android.support.design.widget.CoordinatorLayout;
78
import android.support.design.widget.Snackbar;
89
import android.support.design.widget.TabLayout;
910
import android.support.v7.app.AlertDialog;
@@ -28,6 +29,7 @@
2829
import android.text.Editable;
2930
import android.text.TextWatcher;
3031
import android.util.Log;
32+
import android.view.Gravity;
3133
import android.view.LayoutInflater;
3234
import android.view.View;
3335
import 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,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24.0"
5+
android:viewportHeight="24.0">
6+
<path
7+
android:fillColor="#FF000000"
8+
android:pathData="M12,14c1.66,0 2.99,-1.34 2.99,-3L15,5c0,-1.66 -1.34,-3 -3,-3S9,3.34 9,5v6c0,1.66 1.34,3 3,3zM17.3,11c0,3 -2.54,5.1 -5.3,5.1S6.7,14 6.7,11L5,11c0,3.41 2.72,6.23 6,6.72L11,21h2v-3.28c3.28,-0.48 6,-3.3 6,-6.72h-1.7z"/>
9+
</vector>

app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
tools:context="org.open311.android.MainActivity">
99

1010
<android.support.design.widget.AppBarLayout
11+
android:id="@+id/appbar"
1112
android:layout_width="match_parent"
1213
android:layout_height="wrap_content"
1314
android:theme="@style/AppTheme.AppBarOverlay">

0 commit comments

Comments
 (0)