I can see that Google Place Picker activity can take some time to load (a few seconds) for the first time. So, I want to properly inform user that Google Place Picker is loading.
Now I'm basically creating progress dialog after clicking the button:
progressDialog = new ProgressDialog(this);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setEnabled(false);
progressDialog.setMessage("Loading...");
progressDialog.show();
progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
public void onCancel(DialogInterface arg0) {
//Additional question: How to cancel Place Picker?
}
});
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
try {
startActivityForResult(builder.build(SensorDetailsActivity.this), PLACE_PICKER_REQUEST);
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
}
});
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
And dismissing progress dialog when received a result:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PLACE_PICKER_REQUEST) {
if (resultCode == RESULT_OK) {
//some code
}
}
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setEnabled(true);
progressDialog.dismiss();
}
The problem with that approach is that I can see the progress dialog that I created for a half of a second when I close Place Picker.
Note progress dialog after Place Picker closes.
Is there a better solution for this?