From 04f0b617b0d32ab118115e248c0202e8d37b935e Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Thu, 5 Jan 2012 12:59:16 -0800 Subject: [PATCH] Don't show toast on new user login, fixed keyboard bug on new user login --- .../todoroo/andlib/utility/AndroidUtilities.java | 13 +++++++++++++ .../todoroo/astrid/actfm/ActFmLoginActivity.java | 16 ++++++++++++++-- .../astrid/activity/TaskListActivity.java | 2 ++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/api/src/com/todoroo/andlib/utility/AndroidUtilities.java b/api/src/com/todoroo/andlib/utility/AndroidUtilities.java index 38abeb564..81cf3def7 100644 --- a/api/src/com/todoroo/andlib/utility/AndroidUtilities.java +++ b/api/src/com/todoroo/andlib/utility/AndroidUtilities.java @@ -38,6 +38,7 @@ import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.view.ViewGroup; +import android.view.inputmethod.InputMethodManager; import android.widget.TextView; import com.todoroo.andlib.data.Property; @@ -668,4 +669,16 @@ public class AndroidUtilities { return string.substring(0, 1).toUpperCase() + string.substring(1); } + /** + * Dismiss the keyboard if it is displayed by any of the listed views + * @param context + * @param views - a list of views that might potentially be displaying the keyboard + */ + public static void hideSoftInputForViews(Context context, View...views) { + InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE); + for (View v : views) { + imm.hideSoftInputFromWindow(v.getWindowToken(), 0); + } + } + } diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmLoginActivity.java b/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmLoginActivity.java index 4baac9a35..0897a5b53 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmLoginActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmLoginActivity.java @@ -65,6 +65,7 @@ import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.ExceptionService; +import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DialogUtilities; import com.todoroo.andlib.utility.Preferences; @@ -101,6 +102,9 @@ public class ActFmLoginActivity extends Activity implements AuthListener { private TextView errors; protected boolean noSync = false; + public static final String SHOW_TOAST = "show_toast"; + private boolean showToast; + // --- ui initialization private static final int REQUEST_CODE_GOOGLE_ACCOUNTS = 1; @@ -137,6 +141,8 @@ public class ActFmLoginActivity extends Activity implements AuthListener { rand = new Random(DateUtilities.now()); noSync = getIntent().getBooleanExtra(EXTRA_DO_NOT_SYNC, false); + showToast = getIntent().getBooleanExtra(SHOW_TOAST, true); + facebook = new Facebook(APP_ID); facebookRunner = new AsyncFacebookRunner(facebook); @@ -287,6 +293,7 @@ public class ActFmLoginActivity extends Activity implements AuthListener { public void onClick(DialogInterface dlg, int which) { String nameString = isNew.get() ? name.getText().toString() : null; + AndroidUtilities.hideSoftInputForViews(ActFmLoginActivity.this, name, email, password); authenticate(email.getText().toString(), nameString, ActFmInvoker.PROVIDER_PASSWORD, password.getText().toString()); @@ -296,7 +303,12 @@ public class ActFmLoginActivity extends Activity implements AuthListener { else StatisticsService.reportEvent(StatisticsConstants.ACTFM_SIGNUP_PW); } - }).setNegativeButton(android.R.string.cancel, null).show()); + }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dlg, int which) { + AndroidUtilities.hideSoftInputForViews(ActFmLoginActivity.this, name, email, password); + } + }).show()); dialog.get().setOwnerActivity(ActFmLoginActivity.this); } @@ -471,7 +483,7 @@ public class ActFmLoginActivity extends Activity implements AuthListener { finish(); if (!noSync) { - new ActFmSyncProvider().synchronize(ActFmLoginActivity.this); + new ActFmSyncProvider().synchronize(ActFmLoginActivity.this, showToast); } try { diff --git a/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java b/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java index 302a61b46..b0e603391 100644 --- a/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java @@ -72,6 +72,7 @@ import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.Preferences; import com.todoroo.andlib.widget.GestureService; import com.todoroo.andlib.widget.GestureService.GestureInterface; +import com.todoroo.astrid.actfm.ActFmLoginActivity; import com.todoroo.astrid.actfm.sync.ActFmPreferenceService; import com.todoroo.astrid.actfm.sync.ActFmSyncProvider; import com.todoroo.astrid.activity.SortSelectionActivity.OnSortSelectedListener; @@ -583,6 +584,7 @@ public class TaskListActivity extends ListActivity implements OnScrollListener, if (!Preferences.getBoolean(WelcomeLogin.KEY_SHOWED_WELCOME_LOGIN, false)) { Intent showWelcomeLogin = new Intent(this, WelcomeLogin.class); + showWelcomeLogin.putExtra(ActFmLoginActivity.SHOW_TOAST, false); startActivity(showWelcomeLogin); Preferences.setBoolean(WelcomeLogin.KEY_SHOWED_WELCOME_LOGIN, true); return;