Skip to content

Commit a27589f

Browse files
Fix for #50
1 parent 12eb140 commit a27589f

7 files changed

Lines changed: 125 additions & 88 deletions

File tree

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
<activity
4444
android:name=".MainActivity"
45+
android:windowSoftInputMode="stateHidden|adjustResize"
4546
android:label="@string/app_name"
4647
android:launchMode="singleTop"
4748
android:theme="@style/AppTheme.NoActionBar">

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

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.content.Context;
44
import android.content.SharedPreferences;
5+
import android.graphics.Rect;
56
import android.os.Bundle;
67
import android.support.design.widget.FloatingActionButton;
78
import android.support.design.widget.Snackbar;
@@ -14,13 +15,15 @@
1415
import android.view.LayoutInflater;
1516
import android.view.View;
1617
import android.view.ViewGroup;
18+
import android.view.ViewTreeObserver;
1719
import android.view.WindowManager;
1820
import android.widget.EditText;
1921

2022
import org.open311.android.MainActivity;
2123
import org.open311.android.R;
2224

2325
import static org.open311.android.helpers.Utils.getSettings;
26+
import static org.open311.android.helpers.Utils.hideKeyBoard;
2427
import static org.open311.android.helpers.Utils.saveSetting;
2528

2629
/**
@@ -31,12 +34,9 @@ public class ProfileFragment extends Fragment {
3134
private SharedPreferences settings;
3235
private EditText inputName, inputEmail, inputPhone;
3336
private TextInputLayout inputLayoutName, inputLayoutEmail, inputLayoutPhone;
37+
private FloatingActionButton mHideKeyboard;
3438
private FloatingActionButton mSubmitBtn;
3539

36-
public ProfileFragment() {
37-
// Required empty public constructor
38-
}
39-
4040
@Override
4141
public void onCreate(Bundle savedInstanceState) {
4242
super.onCreate(savedInstanceState);
@@ -46,7 +46,7 @@ public void onCreate(Bundle savedInstanceState) {
4646
@Override
4747
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
4848
Log.d(LOG_TAG, "onCreateView");
49-
View view = inflater.inflate(R.layout.fragment_profile, container, false);
49+
final View view = inflater.inflate(R.layout.fragment_profile, container, false);
5050

5151
inputLayoutName = (TextInputLayout) view.findViewById(R.id.input_layout_name);
5252
inputLayoutEmail = (TextInputLayout) view.findViewById(R.id.input_layout_email);
@@ -71,11 +71,44 @@ public void onClick(View v) {
7171
onSubmitButtonClicked(v);
7272
}
7373
});
74+
mHideKeyboard = (FloatingActionButton) view.findViewById(R.id.profile_keyboard_close);
75+
mHideKeyboard.setOnClickListener(new View.OnClickListener() {
76+
@Override
77+
public void onClick(View v) {
78+
View parent = getActivity().findViewById(R.id.fragment_profile_ll);
79+
parent.clearFocus();
80+
hideKeyBoard(getActivity());
81+
}
82+
});
83+
view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
84+
@Override
85+
public void onGlobalLayout() {
86+
87+
Rect r = new Rect();
88+
view.getWindowVisibleDisplayFrame(r);
89+
int screenHeight = view.getRootView().getHeight();
90+
91+
// r.bottom is the position above soft keypad or device button.
92+
// if keypad is shown, the r.bottom is smaller than that before.
93+
int keypadHeight = screenHeight - r.bottom;
94+
95+
Log.d(LOG_TAG, "keypadHeight = " + keypadHeight);
96+
97+
if (keypadHeight > screenHeight * 0.15) { // 0.15 ratio is perhaps enough to determine keypad height.
98+
// keyboard is opened
99+
mHideKeyboard.setVisibility(View.VISIBLE);
100+
} else {
101+
// keyboard is closed
102+
mHideKeyboard.setVisibility(View.INVISIBLE);
103+
}
104+
}
105+
});
74106

75107
return view;
76108
}
77109

78110
private void onSubmitButtonClicked(View v) {
111+
hideKeyBoard(getActivity());
79112
String result;
80113
if (!validate()) {
81114
return;
@@ -135,7 +168,6 @@ public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2)
135168

136169
@Override
137170
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
138-
139171
}
140172

141173
public void afterTextChanged(Editable editable) {

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

Lines changed: 27 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import android.content.Intent;
1515
import android.content.SharedPreferences;
1616
import android.content.pm.PackageManager;
17-
import android.graphics.Bitmap;
1817
import android.net.Uri;
1918
import android.os.AsyncTask;
2019
import android.os.Build;
@@ -32,7 +31,6 @@
3231
import android.view.View;
3332
import android.view.View.OnClickListener;
3433
import android.view.ViewGroup;
35-
import android.view.WindowManager;
3634
import android.widget.EditText;
3735
import android.widget.ImageView;
3836

@@ -59,7 +57,6 @@
5957
import org.open311.android.R;
6058
import org.open311.android.SoundRecorderActivity;
6159

62-
//import org.open311.android.adapters.AttachmentAdapter;
6360
import org.open311.android.helpers.MyReportsFile;
6461
import org.open311.android.helpers.Utils;
6562
import 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
}
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="#FFFFFFFF"
8+
android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z"/>
9+
</vector>
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="#FFFFFFFF"
8+
android:pathData="M20,3L4,3c-1.1,0 -1.99,0.9 -1.99,2L2,15c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,5c0,-1.1 -0.9,-2 -2,-2zM11,6h2v2h-2L11,6zM11,9h2v2h-2L11,9zM8,6h2v2L8,8L8,6zM8,9h2v2L8,11L8,9zM7,11L5,11L5,9h2v2zM7,8L5,8L5,6h2v2zM16,15L8,15v-2h8v2zM16,11h-2L14,9h2v2zM16,8h-2L14,6h2v2zM19,11h-2L17,9h2v2zM19,8h-2L17,6h2v2zM12,23l4,-4L8,19l4,4z"/>
9+
</vector>

0 commit comments

Comments
 (0)