+\r
+ private abstract static class RightDrawableOnTouchListener implements OnTouchListener {\r
+\r
+ private int fuzz = 75;\r
+ \r
+ /**\r
+ * {@inheritDoc}\r
+ */\r
+ @Override\r
+ public boolean onTouch(View view, MotionEvent event) {\r
+ Drawable rightDrawable = null;\r
+ if (view instanceof TextView) {\r
+ Drawable[] drawables = ((TextView)view).getCompoundDrawables();\r
+ if (drawables.length > 2) {\r
+ rightDrawable = drawables[2];\r
+ }\r
+ }\r
+ if (rightDrawable != null) {\r
+ final int x = (int) event.getX();\r
+ final int y = (int) event.getY();\r
+ final Rect bounds = rightDrawable.getBounds();\r
+ if (x >= (view.getRight() - bounds.width() - fuzz) && x <= (view.getRight() - view.getPaddingRight() + fuzz)\r
+ && y >= (view.getPaddingTop() - fuzz) && y <= (view.getHeight() - view.getPaddingBottom()) + fuzz) {\r
+ \r
+ return onDrawableTouch(event);\r
+ }\r
+ }\r
+ return false;\r
+ }\r
+\r
+ public abstract boolean onDrawableTouch(final MotionEvent event);\r
+ }\r
+\r
+\r
+ public void onSamlDialogSuccess(String sessionCookie){\r
+ mAuthToken = sessionCookie;\r
+ \r
+ if (sessionCookie != null && sessionCookie.length() > 0) {\r
+ mAuthToken = sessionCookie;\r
+ boolean success = true;\r
+ if (mAction == ACTION_CREATE) {\r
+ success = createAccount();\r
+ \r
+ } else {\r
+ updateToken();\r
+ }\r
+ if (success) {\r
+ finish();\r
+ }\r
+ }\r
+\r
+ \r
+ }\r
+\r
+\r
+ @Override\r
+ public void onSsoFinished(String sessionCookies) {\r
+ //Toast.makeText(this, "got cookies: " + sessionCookie, Toast.LENGTH_LONG).show();\r
+\r
+ if (sessionCookies != null && sessionCookies.length() > 0) {\r
+ Log_OC.d(TAG, "Successful SSO - time to save the account");\r
+ onSamlDialogSuccess(sessionCookies);\r
+ Fragment fd = getSupportFragmentManager().findFragmentByTag(TAG_SAML_DIALOG);\r
+ if (fd != null && fd instanceof SherlockDialogFragment) {\r
+ Dialog d = ((SherlockDialogFragment)fd).getDialog();\r
+ if (d != null && d.isShowing()) {\r
+ d.dismiss();\r
+ }\r
+ }\r
+\r
+ } else { \r
+ // TODO - show fail\r
+ Log_OC.d(TAG, "SSO failed");\r
+ }\r
+ \r
+ }\r
+ \r
+\r
+ private void syncAccount(){\r
+ /// immediately request for the synchronization of the new account\r
+ Bundle bundle = new Bundle();\r
+ bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);\r
+ ContentResolver.requestSync(mAccount, AccountAuthenticator.AUTHORITY, bundle);\r
+ }\r
+ \r
+ @Override\r
+ public boolean onTouchEvent(MotionEvent event) {\r
+ if (AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(mAuthTokenType) &&\r
+ mHostUrlInput.hasFocus() && event.getAction() == MotionEvent.ACTION_DOWN) {\r
+ checkOcServer();\r
+ }\r
+ return super.onTouchEvent(event);\r
+ }\r