List of usage examples for android.webkit CookieSyncManager createInstance
public static CookieSyncManager createInstance(Context context)
From source file:com.andrewshu.android.reddit.mail.InboxListActivity.java
/** * Called when the activity starts up. Do activity initialization * here, not in a constructor./* w w w . jav a 2 s. c o m*/ * * @see Activity#onCreate */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); CookieSyncManager.createInstance(getApplicationContext()); mSettings.loadRedditPreferences(this, mClient); setRequestedOrientation(mSettings.getRotation()); setTheme(mSettings.getTheme()); requestWindowFeature(Window.FEATURE_PROGRESS); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.inbox_list_content); registerForContextMenu(getListView()); if (mSettings.isLoggedIn()) { if (savedInstanceState != null) { mReplyTargetName = savedInstanceState.getString(Constants.REPLY_TARGET_NAME_KEY); mAfter = savedInstanceState.getString(Constants.AFTER_KEY); mBefore = savedInstanceState.getString(Constants.BEFORE_KEY); mCount = savedInstanceState.getInt(Constants.THREAD_COUNT_KEY); mLastAfter = savedInstanceState.getString(Constants.LAST_AFTER_KEY); mLastBefore = savedInstanceState.getString(Constants.LAST_BEFORE_KEY); mLastCount = savedInstanceState.getInt(Constants.THREAD_LAST_COUNT_KEY); mVoteTargetThingInfo = savedInstanceState.getParcelable(Constants.VOTE_TARGET_THING_INFO_KEY); mWhichInbox = savedInstanceState.getString(Constants.WHICH_INBOX_KEY); restoreLastNonConfigurationInstance(); if (mMessagesList == null) { // Load previous view of threads if (mLastAfter != null) { new DownloadMessagesTask(mWhichInbox, mLastAfter, null, mLastCount) .execute(Constants.DEFAULT_COMMENT_DOWNLOAD_LIMIT); } else if (mLastBefore != null) { new DownloadMessagesTask(mWhichInbox, null, mLastBefore, mLastCount) .execute(Constants.DEFAULT_COMMENT_DOWNLOAD_LIMIT); } else { new DownloadMessagesTask(mWhichInbox).execute(Constants.DEFAULT_COMMENT_DOWNLOAD_LIMIT); } } else { // Orientation change. Use prior instance. resetUI(new MessagesListAdapter(this, mMessagesList)); } } else { Bundle extras = getIntent().getExtras(); if (extras != null) { if (extras.containsKey(Constants.WHICH_INBOX_KEY)) mWhichInbox = extras.getString(Constants.WHICH_INBOX_KEY); } new DownloadMessagesTask(mWhichInbox).execute(Constants.DEFAULT_COMMENT_DOWNLOAD_LIMIT); } } else { showDialog(Constants.DIALOG_LOGIN); } setTitle(String.format(getResources().getString(R.string.inbox_title), mSettings.getUsername())); }
From source file:com.kaixin.connect.Kaixin.java
/** * access_token(User-Agent Flow)/*from w w w . java2s. com*/ * * @param context * @param permissions * http://wiki.open.kaixin001.com/index.php?id=OAuth%E6%96% * 87%E6%A1%A3#REST%E6% * 8E%A5%E5%8F%A3%E5%92%8COAuth%E6%9D%83%E9%99%90%E5%AF%B9%E7%85% * A 7%E8%A1%A8 * @param listener * @param redirectUrl * @param responseType */ private void authorize(final Context context, String[] permissions, final KaixinAuthListener listener, final String redirectUrl, String responseType) { CookieSyncManager.createInstance(context); Bundle params = new Bundle(); params.putString("client_id", API_KEY); params.putString("response_type", responseType); params.putString("redirect_uri", redirectUrl); params.putString("state", ""); params.putString("display", "page"); params.putString("oauth_client", "1"); if (permissions != null && permissions.length > 0) { String scope = TextUtils.join(" ", permissions); params.putString("scope", scope); } String url = KX_AUTHORIZE_URL + "?" + Util.encodeUrl(params); if (context .checkCallingOrSelfPermission(Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED) { Util.showAlert(context, "", ""); } else { new KaixinDialog(context, url, new KaixinDialogListener() { @Override public int onPageBegin(String url) { return KaixinDialogListener.DIALOG_PROCCESS; } @Override public void onPageFinished(String url) { } @Override public boolean onPageStart(String url) { return (KaixinDialogListener.PROCCESSED == parseUrl(url)); } @Override public void onReceivedError(int errorCode, String description, String failingUrl) { listener.onAuthError(new KaixinAuthError(String.valueOf(errorCode), description, failingUrl)); } private int parseUrl(String url) { if (url.startsWith(KX_AUTHORIZE_CALLBACK_URL)) { Bundle values = Util.parseUrl(url); String error = values.getString("error");// if (error != null) { if (ACCESS_DENIED.equalsIgnoreCase(error)) { listener.onAuthCancel(values); } else if (LOGIN_DENIED.equalsIgnoreCase(error)) { listener.onAuthCancelLogin(); } else { listener.onAuthError(new KaixinAuthError(error, error, url)); } Util.clearCookies(context); setAccessToken(null); setRefreshToken(null); setAccessExpires(0L); } else { this.authComplete(values, url); } return KaixinDialogListener.PROCCESSED; } return KaixinDialogListener.UNPROCCESS; } private void authComplete(Bundle values, String url) { CookieSyncManager.getInstance().sync(); String accessToken = values.getString(ACCESS_TOKEN); String refreshToken = values.getString(REFRESH_TOKEN); String expiresIn = values.getString(EXPIRES_IN); if (accessToken != null && refreshToken != null && expiresIn != null) { try { setAccessToken(accessToken); setRefreshToken(refreshToken); setAccessExpiresIn(expiresIn); listener.onAuthComplete(values); } catch (Exception e) { listener.onAuthError( new KaixinAuthError(e.getClass().getName(), e.getMessage(), e.toString())); } } else { listener.onAuthError(new KaixinAuthError("", "", url)); } } }).show(); } }
From source file:br.com.ufc.palestrasufc.twitter.Util.java
public static void clearCookies(Context context) { // Edge case: an illegal state exception is thrown if an instance of // CookieSyncManager has not be created. CookieSyncManager is normally // created by a WebKit view, but this might happen if you start the // app, restore saved state, and click logout before running a UI // dialog in a WebView -- in which case the app crashes @SuppressWarnings("unused") CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(context); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie();//w w w . ja v a2s. c o m }
From source file:com.easy.facebook.android.facebook.FBLoginManager.java
private void startDialogAuth(Activity activityDialog, String[] permissions) throws EasyFacebookError { Bundle params = new Bundle(); if (permissions.length > 0) { params.putString("scope", TextUtils.join(",", permissions)); }//from w w w . jav a 2 s . com CookieSyncManager.createInstance(activityDialog); dialog(activityDialog, "oauth", params, new LoginListener() { public void loginSuccess(Facebook facebook) { CookieSyncManager.getInstance().sync(); ((LoginListener) activity).loginSuccess(facebook); } public void logoutSuccess() { ((LoginListener) activity).logoutSuccess(); } public void loginFail() { ((LoginListener) activity).loginFail(); } }); }
From source file:com.ds.kaixin.Kaixin.java
/** * access_token(User-Agent Flow)//from w ww . jav a 2s . co m * * @param context * @param permissions * ?http://wiki.open.kaixin001.com/index.php?id=OAuth%E6% * 96% 87%E6%A1%A3#REST%E6% * 8E%A5%E5%8F%A3%E5%92%8COAuth%E6%9D%83%E9%99%90%E5%AF%B9%E7%85% * A 7%E8%A1%A8 * @param listener * @param redirectUrl * @param responseType */ private void authorize(final Context context, String[] permissions, final KaixinAuthListener listener, final String redirectUrl, String responseType) { CookieSyncManager.createInstance(context); Bundle params = new Bundle(); params.putString("client_id", API_KEY); params.putString("response_type", responseType); params.putString("redirect_uri", redirectUrl); params.putString("state", ""); params.putString("display", "page"); params.putString("oauth_client", "1"); if (permissions != null && permissions.length > 0) { String scope = TextUtils.join(" ", permissions); params.putString("scope", scope); } String url = KX_AUTHORIZE_URL + "?" + Util.encodeUrl(params); if (context .checkCallingOrSelfPermission(Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED) { Util.showAlert(context, "", "??"); } else { new KaixinDialog(context, url, new KaixinDialogListener() { public int onPageBegin(String url) { return KaixinDialogListener.DIALOG_PROCCESS; } public void onPageFinished(String url) { } public boolean onPageStart(String url) { return (KaixinDialogListener.PROCCESSED == parseUrl(url)); } public void onReceivedError(int errorCode, String description, String failingUrl) { listener.onAuthError(new KaixinAuthError(String.valueOf(errorCode), description, failingUrl)); } private int parseUrl(String url) { if (url.startsWith(KX_AUTHORIZE_CALLBACK_URL)) { Bundle values = Util.parseUrl(url); String error = values.getString("error");// if (error != null) { if (ACCESS_DENIED.equalsIgnoreCase(error)) { listener.onAuthCancel(values); } else if (LOGIN_DENIED.equalsIgnoreCase(error)) { listener.onAuthCancelLogin(); } else { listener.onAuthError(new KaixinAuthError(error, error, url)); } Util.clearCookies(context); setAccessToken(null); setRefreshToken(null); setAccessExpires(0L); } else { this.authComplete(values, url); } return KaixinDialogListener.PROCCESSED; } return KaixinDialogListener.UNPROCCESS; } private void authComplete(Bundle values, String url) { CookieSyncManager.getInstance().sync(); String accessToken = values.getString(ACCESS_TOKEN); String refreshToken = values.getString(REFRESH_TOKEN); String expiresIn = values.getString(EXPIRES_IN); if (accessToken != null && refreshToken != null && expiresIn != null) { try { setAccessToken(accessToken); setRefreshToken(refreshToken); setAccessExpiresIn(expiresIn); listener.onAuthComplete(values); } catch (Exception e) { listener.onAuthError( new KaixinAuthError(e.getClass().getName(), e.getMessage(), e.toString())); } } else { listener.onAuthError(new KaixinAuthError("", "", url)); } } }).show(); } }
From source file:in.shick.diode.user.ProfileActivity.java
/** * Called when the activity starts up. Do activity initialization * here, not in a constructor./*from w w w .j a v a2 s . c o m*/ * * @see Activity#onCreate */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); CookieSyncManager.createInstance(getApplicationContext()); mSettings.loadRedditPreferences(this, mClient); setRequestedOrientation(mSettings.getRotation()); setTheme(mSettings.getTheme()); requestWindowFeature(Window.FEATURE_PROGRESS); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.profile_list_content); registerForContextMenu(getListView()); if (savedInstanceState != null) { if (Constants.LOGGING) Log.d(TAG, "using savedInstanceState"); mUsername = savedInstanceState.getString(Constants.USERNAME_KEY); mAfter = savedInstanceState.getString(Constants.AFTER_KEY); mBefore = savedInstanceState.getString(Constants.BEFORE_KEY); mCount = savedInstanceState.getInt(Constants.THREAD_COUNT_KEY); mLastAfter = savedInstanceState.getString(Constants.LAST_AFTER_KEY); mLastBefore = savedInstanceState.getString(Constants.LAST_BEFORE_KEY); mLastCount = savedInstanceState.getInt(Constants.THREAD_LAST_COUNT_KEY); mKarma = savedInstanceState.getIntArray(Constants.KARMA_KEY); mSortByUrl = savedInstanceState.getString(Constants.CommentsSort.SORT_BY_KEY); mJumpToThreadId = savedInstanceState.getString(Constants.JUMP_TO_THREAD_ID_KEY); mVoteTargetThingInfo = savedInstanceState.getParcelable(Constants.VOTE_TARGET_THING_INFO_KEY); // try to restore mThingsList using getLastNonConfigurationInstance() // (separate function to avoid a compiler warning casting ArrayList<ThingInfo> restoreLastNonConfigurationInstance(); if (mThingsList == null) { // Load previous page of profile items if (mLastAfter != null) { new DownloadProfileTask(mUsername, mLastAfter, null, mLastCount).execute(); } else if (mLastBefore != null) { new DownloadProfileTask(mUsername, null, mLastBefore, mLastCount).execute(); } else { new DownloadProfileTask(mUsername).execute(); } } else { // Orientation change. Use prior instance. resetUI(new ThingsListAdapter(this, mThingsList)); setTitle(String.format(getResources().getString(R.string.user_profile), mUsername)); } return; } // Handle subreddit Uri passed via Intent else if (getIntent().getData() != null) { Matcher userPathMatcher = USER_PATH_PATTERN.matcher(getIntent().getData().getPath()); if (userPathMatcher.matches()) { mUsername = userPathMatcher.group(1); new DownloadProfileTask(mUsername).execute(); return; } } // No username specified by Intent, so load the logged in user's profile if (mSettings.isLoggedIn()) { mUsername = mSettings.getUsername(); new DownloadProfileTask(mUsername).execute(); return; } // Can't find a username to use. Quit. if (Constants.LOGGING) Log.e(TAG, "Could not find a username to use for ProfileActivity"); finish(); }
From source file:com.social_api.facebook.core.Util.java
public static void clearCookies(Context context) { // Edge case: an illegal state exception is thrown if an instance of // CookieSyncManager has not be created. CookieSyncManager is normally // created by a WebKit view, but this might happen if you hasStarted the // app, restore saved state, and click logout before running a UI // dialog in a WebView -- in which case the app crashes @SuppressWarnings("unused") CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(context); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie();/* www . j a v a2 s . com*/ }
From source file:com.polyvi.xface.extension.xmlhttprequest.XXMLHttpRequest.java
/** * cookie//from w ww .ja v a 2s. co m * * @param url * url? */ private void addCookie(String url) { // cookie? CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(mContext); cookieSyncManager.startSync(); String cookie = CookieManager.getInstance().getCookie(url); if (cookie != null) { mRequestHeaders.put("Cookie", cookie); } }
From source file:com.ztspeech.weibo.sdk.kaixin.Kaixin.java
/** * access_token(User-Agent Flow)/*from w ww.jav a2 s .c o m*/ * * @param context * @param permissions * http://wiki.open.kaixin001.com/index.php?id=OAuth%E6%96 * % 87%E6%A1%A3#REST%E6% * 8E%A5%E5%8F%A3%E5%92%8COAuth%E6%9D%83%E9%99%90%E5%AF%B9%E7%85% * A 7%E8%A1%A8 * @param listener * @param redirectUrl * @param responseType */ private void authorize(final Context context, String[] permissions, final KaixinAuthListener listener, final String redirectUrl, String responseType) { CookieSyncManager.createInstance(context); Bundle params = new Bundle(); params.putString("client_id", API_KEY); params.putString("response_type", responseType); params.putString("redirect_uri", redirectUrl); params.putString("state", ""); params.putString("display", "page"); params.putString("oauth_client", "1"); if (permissions != null && permissions.length > 0) { String scope = TextUtils.join(" ", permissions); params.putString("scope", scope); } String url = KX_AUTHORIZE_URL + "?" + Util.encodeUrl(params); if (context .checkCallingOrSelfPermission(Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED) { Util.showAlert(context, "", ""); } else { new KaixinDialog(context, url, new KaixinDialogListener() { @Override public int onPageBegin(String url) { return KaixinDialogListener.DIALOG_PROCCESS; } @Override public void onPageFinished(String url) { } @Override public boolean onPageStart(String url) { return (KaixinDialogListener.PROCCESSED == parseUrl(url)); } @Override public void onReceivedError(int errorCode, String description, String failingUrl) { listener.onAuthError(new KaixinAuthError(String.valueOf(errorCode), description, failingUrl)); } private int parseUrl(String url) { if (url.startsWith(KX_AUTHORIZE_CALLBACK_URL)) { Bundle values = Util.parseUrl(url); String error = values.getString("error");// if (error != null) { if (ACCESS_DENIED.equalsIgnoreCase(error)) { listener.onAuthCancel(values); } else if (LOGIN_DENIED.equalsIgnoreCase(error)) { listener.onAuthCancelLogin(); } else { listener.onAuthError(new KaixinAuthError(error, error, url)); } Util.clearCookies(context); setAccessToken(null); setRefreshToken(null); setAccessExpires(0L); } else { this.authComplete(values, url); } return KaixinDialogListener.PROCCESSED; } return KaixinDialogListener.UNPROCCESS; } private void authComplete(Bundle values, String url) { CookieSyncManager.getInstance().sync(); String accessToken = values.getString(ACCESS_TOKEN); String refreshToken = values.getString(REFRESH_TOKEN); String expiresIn = values.getString(EXPIRES_IN); if (accessToken != null && refreshToken != null && expiresIn != null) { try { setAccessToken(accessToken); setRefreshToken(refreshToken); setAccessExpiresIn(expiresIn); updateStorage(context); listener.onAuthComplete(values); } catch (Exception e) { listener.onAuthError( new KaixinAuthError(e.getClass().getName(), e.getMessage(), e.toString())); } } else { listener.onAuthError(new KaixinAuthError("", "", url)); } } }).show(); } }
From source file:com.captix.scan.social.facebook.Util.java
public static void clearCookies(Context context) { // Edge case: an illegal state exception is thrown if an instance of // CookieSyncManager has not be created. CookieSyncManager is normally // created by a WebKit view, but this might happen if you start the // app, restore saved state, and click logout before running a UI // dialog in a WebView -- in which case the app crashes @SuppressWarnings("unused") CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(context); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie();/*from www. jav a 2 s . c om*/ }