1414import android .content .Intent ;
1515import android .content .SharedPreferences ;
1616import android .content .pm .PackageManager ;
17- import android .graphics .Bitmap ;
1817import android .net .Uri ;
1918import android .os .AsyncTask ;
2019import android .os .Build ;
3231import android .view .View ;
3332import android .view .View .OnClickListener ;
3433import android .view .ViewGroup ;
35- import android .view .WindowManager ;
3634import android .widget .EditText ;
3735import android .widget .ImageView ;
3836
5957import org .open311 .android .R ;
6058import org .open311 .android .SoundRecorderActivity ;
6159
62- //import org.open311.android.adapters.AttachmentAdapter;
6360import org .open311 .android .helpers .MyReportsFile ;
6461import org .open311 .android .helpers .Utils ;
6562import org .open311 .android .models .Attachment ;
@@ -120,6 +117,7 @@ public class ReportFragment extends Fragment {
120117 private ViewSwitcher photoviewSwitcher ;
121118 private ViewSwitcher audioviewSwitcher ;
122119 private AudioStatus mAudioStatus ;
120+ private FloatingActionButton mHideKeyboard ;
123121 private FloatingActionButton mSubmitBtn ;
124122 private EditText mDescriptionView ;
125123 private int mPlayTime = 0 ;
@@ -151,10 +149,6 @@ public String toString() {
151149 }
152150 }
153151
154- public ReportFragment () {
155- // Required empty public constructor
156- }
157-
158152 @ Override
159153 public View onCreateView (LayoutInflater inflater , ViewGroup container , Bundle state ) {
160154 Log .d (LOG_TAG , "onCreateView" );
@@ -169,19 +163,24 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle st
169163 playBtn = (ImageView ) view .findViewById (R .id .audioView2 );
170164 mDescriptionView = (EditText ) view .findViewById (R .id .report_description_textbox );
171165 mSubmitBtn = (FloatingActionButton ) view .findViewById (R .id .report_submit );
166+ mHideKeyboard = (FloatingActionButton ) view .findViewById (R .id .report_keyboard_close );
172167 photoviewSwitcher = (ViewSwitcher ) view .findViewById (R .id .report_photoviewswitcher );
173168 audioviewSwitcher = (ViewSwitcher ) view .findViewById (R .id .report_audioviewswitcher );
174169 ImageView photoPlaceholder = (ImageView ) view .findViewById ((R .id .photoPlaceholder ));
175170
176- new RetrieveServicesTask (). execute (); // Load services-list in the background
177- //Hide the keyboard unless the descriptionView is selected
171+ // Load services-list in the background
172+ new RetrieveServicesTask (). execute ();
178173 mDescriptionView .setOnFocusChangeListener (new View .OnFocusChangeListener () {
179174 @ Override
180175 public void onFocusChange (View v , boolean hasFocus ) {
181176 if (!hasFocus ) {
177+ //Hide a close keyboard button
178+ mHideKeyboard .setVisibility (View .INVISIBLE );
182179 v .clearFocus ();
183180 hideKeyBoard (getActivity ());
184181 } else {
182+ //Show a close keyboard Button
183+ mHideKeyboard .setVisibility (View .VISIBLE );
185184 mDescriptionView .addTextChangedListener (new TextWatcher () {
186185 @ Override
187186 public void beforeTextChanged (CharSequence charSequence , int i , int i1 , int i2 ) {
@@ -262,6 +261,14 @@ public void onClick(View v) {
262261 onSubmitButtonClicked ();
263262 }
264263 });
264+ mHideKeyboard .setOnClickListener (new OnClickListener () {
265+ @ Override
266+ public void onClick (View v ) {
267+ mHideKeyboard .setVisibility (View .INVISIBLE );
268+ mDescriptionView .clearFocus ();
269+ hideKeyBoard (getActivity ());
270+ }
271+ });
265272
266273 return view ;
267274 }
@@ -273,7 +280,7 @@ private void updateService() {
273280 ImageView icon = (ImageView ) getActivity ().findViewById (R .id .serviceView );
274281 icon .setColorFilter (ContextCompat .getColor (getContext (), R .color .colorAccent ), android .graphics .PorterDuff .Mode .MULTIPLY );
275282 }
276- validate (); //required, so validate
283+ validate ();
277284 }
278285
279286 private void updateLocation () {
@@ -429,13 +436,6 @@ public void onCreate(Bundle savedInstanceState) {
429436 attrInfoList = new LinkedList <AttributeInfo >();
430437 attachments = new LinkedList <Attachment >();
431438 installationId = ((MainActivity ) getActivity ()).getInstallationId ();
432-
433- // Don't show the keyboard if it isn't already shown,
434- // but if it was open when entering the activity, leave it open.
435- // To always hide the keyboard when the activity starts: SOFT_INPUT_STATE_ALWAYS_HIDDEN
436- getActivity ().getWindow ().setSoftInputMode (
437- WindowManager .LayoutParams .SOFT_INPUT_STATE_UNCHANGED );
438-
439439 }
440440
441441 @ Override
@@ -742,7 +742,6 @@ private void onLocationButtonClicked() {
742742 }
743743
744744 private void handleLocation () {
745- // todo, save to the backstack so that when we get back, we remain where we were.
746745 Intent intent = new Intent (getActivity (), MapActivity .class );
747746 startActivityForResult (intent , LOCATION_REQUEST );
748747 }
@@ -872,33 +871,15 @@ private void onSubmitButtonClicked() {
872871 Normalizer .normalize (
873872 mDescriptionView .getText ().toString (), Normalizer .Form .NFD )
874873 .replaceAll (pattern , "" ));
875-
876- // todo, if single attachment and the type is image
877- // if (imageUri != null) {
878- // Glide.with(getActivity().getApplicationContext())
879- // .load(imageUri)
880- // .asBitmap()
881- // .diskCacheStrategy(DiskCacheStrategy.SOURCE)
882- // .into(new SimpleTarget<Bitmap>() {
883- // @Override
884- // public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
885- // PostServiceRequestTask bgTask = new PostServiceRequestTask(data, bitmap);
886- // bgTask.execute();
887- // }
888- // });
889- // } else {
890-
891- PostServiceRequestTask bgTask = new PostServiceRequestTask (data , null );
874+ PostServiceRequestTask bgTask = new PostServiceRequestTask (data );
892875 bgTask .execute ();
893- // }
894876 } else {
895877
896878 AlertDialog .Builder builder = new AlertDialog .Builder (getContext (), R .style .AppTheme_Dialog );
897879 builder .setTitle (getString (R .string .post_anonymous ))
898880 .setMessage (getString (R .string .post_anonymous_description ))
899881 .setPositiveButton (getString (R .string .yes ), new DialogInterface .OnClickListener () {
900882 public void onClick (DialogInterface dialog , int which ) {
901- // TODO redirect to profile
902883 TabLayout tabLayout = (TabLayout ) getActivity ().findViewById (R .id .tabs );
903884 TabLayout .Tab tab = tabLayout .getTabAt (2 );
904885 if (tab != null ) {
@@ -913,23 +894,8 @@ public void onClick(DialogInterface dialog, int which) {
913894 .setDescription (Normalizer .normalize (
914895 mDescriptionView .getText ().toString (), Normalizer .Form .NFD )
915896 .replaceAll (pattern , "" ));
916-
917- // if (imageUri != null) {
918- // Glide.with(getActivity().getApplicationContext())
919- // .load(imageUri)
920- // .asBitmap()
921- // .diskCacheStrategy(DiskCacheStrategy.SOURCE)
922- // .into(new SimpleTarget<Bitmap>() {
923- // @Override
924- // public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
925- // PostServiceRequestTask bgTask = new PostServiceRequestTask(data, bitmap);
926- // bgTask.execute();
927- // }
928- // });
929- // } else {
930- PostServiceRequestTask bgTask = new PostServiceRequestTask (data , null );
897+ PostServiceRequestTask bgTask = new PostServiceRequestTask (data );
931898 bgTask .execute ();
932- // }
933899 }
934900 })
935901 .show ();
@@ -968,11 +934,11 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
968934
969935 if (requestCode == CAMERA_REQUEST ) {
970936 if (resultCode == Activity .RESULT_OK ) {
971- if (data != null ) {
937+ if (data != null ) {
972938 if (data .getData () == null ) return ;
973939 updatePhoto (data .getData (), true );
974940 } else {
975- if (photo .length () == 0 ) return ;
941+ if (photo .length () == 0 ) return ;
976942 updatePhoto (Uri .fromFile (photo ), true );
977943 }
978944 } else {
@@ -995,12 +961,10 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
995961 private class PostServiceRequestTask extends AsyncTask <Void , Void , String > {
996962
997963 private POSTServiceRequestData data ;
998- private Bitmap bitmap ;
999964 private boolean success = true ;
1000965
1001- PostServiceRequestTask (POSTServiceRequestData data , Bitmap bitmap ) {
966+ PostServiceRequestTask (POSTServiceRequestData data ) {
1002967 this .data = data ;
1003- this .bitmap = bitmap ;
1004968 }
1005969
1006970 /**
@@ -1013,7 +977,6 @@ protected String doInBackground(Void... ignore) {
1013977 String result ;
1014978
1015979 try {
1016- // todo send check and send attachments first! Use url's retrieved for the final post.
1017980 if (attachments .size () > 0 ) {
1018981 final OkHttpClient client = new OkHttpClient ();
1019982
@@ -1219,7 +1182,7 @@ protected List<Service> doInBackground(String... params) {
12191182 APIWrapper wrapper ;
12201183 EndpointType endpointType ;
12211184 Server currentServer = ((MainActivity ) getActivity ()).getCurrentServer ();
1222- // todo Check if server has a base URL, then check if it has a test Url. determine the EndpointType by that.
1185+ // TODO Check if server has a base URL, then check if it has a test Url. determine the EndpointType by that.
12231186 endpointType = EndpointType .PRODUCTION ;
12241187
12251188 try {
@@ -1244,7 +1207,6 @@ protected void onPostExecute(List<Service> result) {
12441207 progressDialog .setMessage ("All done!" );
12451208 Log .d (LOG_TAG , "RetrieveServicesTask onPostExecute - Result: " + result );
12461209 if (result != null ) {
1247- // todo, reactivate the services list on the Report Fragment
12481210 services = result ;
12491211 resetAll ();
12501212 } else {
@@ -1341,12 +1303,11 @@ private File createFile(Attachment.AttachmentType type) throws IOException {
13411303 String timeStamp = new SimpleDateFormat ("yyyyMMdd_HHmmss" , Locale .US ).format (new Date ());
13421304 String fileName = prefix + timeStamp + "_" ;
13431305
1344- File file = File .createTempFile (
1345- fileName , /* prefix */
1346- extension , /* suffix */
1347- storageDir /* directory */
1306+ return File .createTempFile (
1307+ fileName ,
1308+ extension ,
1309+ storageDir
13481310 );
1349- return file ;
13501311 }
13511312
13521313}
0 commit comments