Fixing the closing of send to google dialogs.

This commit is contained in:
Rodrigo Damazio
2011-06-27 05:20:54 -03:00
parent 358fb87683
commit 44fea0117d
3 changed files with 32 additions and 11 deletions
@@ -1,12 +1,12 @@
/* /*
* Copyright 2010 Google Inc. * Copyright 2010 Google Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of * use this file except in compliance with the License. You may obtain a copy of
* the License at * the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -52,7 +52,7 @@ public class AccountChooser {
* If no account is found the user will be alerted. * If no account is found the user will be alerted.
* If only one account is found that will be used. * If only one account is found that will be used.
* If multiple accounts are found the user will be allowed to choose. * If multiple accounts are found the user will be allowed to choose.
* *
* @param activity The parent activity * @param activity The parent activity
* @param handler The handler to be notified when an account has been selected * @param handler The handler to be notified when an account has been selected
*/ */
@@ -83,13 +83,18 @@ public class AccountChooser {
builder.setPositiveButton(R.string.ok, builder.setPositiveButton(R.string.ok,
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
selectedAccount = accounts[selectedAccountIndex]; dialog.dismiss();
if (selectedAccountIndex >= 0) {
selectedAccount = accounts[selectedAccountIndex];
}
handler.handleAccountSelected(selectedAccount); handler.handleAccountSelected(selectedAccount);
} }
}); });
builder.setNegativeButton(R.string.cancel, builder.setNegativeButton(R.string.cancel,
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
handler.handleAccountSelected(null); handler.handleAccountSelected(null);
} }
}); });
@@ -120,6 +125,7 @@ public class AccountChooser {
builder.setNegativeButton(R.string.ok, builder.setNegativeButton(R.string.ok,
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
handler.handleAccountSelected(null); handler.handleAccountSelected(null);
} }
}); });
@@ -1,12 +1,12 @@
/* /*
* Copyright 2011 Google Inc. * Copyright 2011 Google Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of * use this file except in compliance with the License. You may obtain a copy of
* the License at * the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -90,6 +90,8 @@ public class MyMapsList extends Activity implements MapsFacade.MapsListCallback
// The user did not quit and there was a valid google // The user did not quit and there was a valid google
// account. // account.
doLogin(account); doLogin(account);
} else {
finish();
} }
} }
}); });
@@ -112,6 +112,7 @@ public class SendActivity extends Activity implements ProgressIndicator {
@Override @Override
protected void onStart() { protected void onStart() {
Log.d(TAG, "SendActivity.onStart");
super.onStart(); super.onStart();
resetState(); resetState();
@@ -152,6 +153,7 @@ public class SendActivity extends Activity implements ProgressIndicator {
@Override @Override
protected void onStop() { protected void onStop() {
Log.d(TAG, "SendActivity.onStop");
tracker.dispatch(); tracker.dispatch();
tracker.stop(); tracker.stop();
@@ -403,18 +405,27 @@ public class SendActivity extends Activity implements ProgressIndicator {
final boolean canShare = sendToFusionTablesTableId != null final boolean canShare = sendToFusionTablesTableId != null
|| sendToMyMapsMapId != null; || sendToMyMapsMapId != null;
final OnClickListener finishListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
finish();
}
};
DialogInterface.OnClickListener doShareListener = null; DialogInterface.OnClickListener doShareListener = null;
if (canShare) { if (canShare) {
doShareListener = new DialogInterface.OnClickListener() { doShareListener = new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
shareLinkToMap(sentToMyMaps, sentToFusionTables); shareLinkToMap(sentToMyMaps, sentToFusionTables);
finishListener.onClick(dialog, which);
} }
}; };
} }
DialogInterface.OnClickListener onOkListener = (canShare && shareRequested) DialogInterface.OnClickListener onOkListener = (canShare && shareRequested)
? doShareListener : null; ? doShareListener : finishListener;
DialogInterface.OnClickListener onShareListener = (canShare && !shareRequested) DialogInterface.OnClickListener onShareListener = (canShare && !shareRequested)
? doShareListener : null; ? doShareListener : null;
@@ -523,7 +534,8 @@ public class SendActivity extends Activity implements ProgressIndicator {
public void handleAccountSelected(Account account) { public void handleAccountSelected(Account account) {
if (account == null) { if (account == null) {
progressDialog.dismiss(); progressDialog.dismiss();
return; progressDialog = null;
finish();
} }
doLogin(results, requestCode, service, account); doLogin(results, requestCode, service, account);
@@ -533,9 +545,10 @@ public class SendActivity extends Activity implements ProgressIndicator {
private void doLogin(final Intent results, final int requestCode, private void doLogin(final Intent results, final int requestCode,
final String service, final Account account) { final String service, final Account account) {
// There's a chance that we go to a different activity, so close the dialog.
lastAuth.doLogin(new Runnable() { lastAuth.doLogin(new Runnable() {
public void run() { public void run() {
Log.i(TAG, "Loggin success for " + service + "!"); Log.i(TAG, "Login success for " + service + "!");
onActivityResult(requestCode, RESULT_OK, results); onActivityResult(requestCode, RESULT_OK, results);
} }
}, account); }, account);