Example usage for android.webkit CookieSyncManager getInstance

List of usage examples for android.webkit CookieSyncManager getInstance

Introduction

In this page you can find the example usage for android.webkit CookieSyncManager getInstance.

Prototype

public static CookieSyncManager getInstance() 

Source Link

Document

Singleton access to a CookieSyncManager .

Usage

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.ja  v a 2  s  . c  o m*/
    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.andrewshu.android.reddit.common.Common.java

static void clearCookies(RedditSettings settings, HttpClient client, Context context) {
    settings.setRedditSessionCookie(null);

    RedditIsFunHttpClientFactory.getCookieStore().clear();
    CookieSyncManager.getInstance().sync();

    SharedPreferences sessionPrefs = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = sessionPrefs.edit();
    editor.remove("reddit_sessionValue");
    editor.remove("reddit_sessionDomain");
    editor.remove("reddit_sessionPath");
    editor.remove("reddit_sessionExpiryDate");
    editor.commit();/*from www.ja  v  a 2 s . co  m*/
}

From source file:com.andrewshu.android.reddit.settings.RedditSettings.java

public void loadRedditPreferences(Context context, HttpClient client) {
    // Session//w  w w. j  av a  2 s.  c  o  m
    SharedPreferences sessionPrefs = PreferenceManager.getDefaultSharedPreferences(context);
    this.setUsername(sessionPrefs.getString("username", null));
    this.setModhash(sessionPrefs.getString("modhash", null));
    String cookieValue = sessionPrefs.getString("reddit_sessionValue", null);
    String cookieDomain = sessionPrefs.getString("reddit_sessionDomain", null);
    String cookiePath = sessionPrefs.getString("reddit_sessionPath", null);
    long cookieExpiryDate = sessionPrefs.getLong("reddit_sessionExpiryDate", -1);
    if (cookieValue != null) {
        BasicClientCookie redditSessionCookie = new BasicClientCookie("reddit_session", cookieValue);
        redditSessionCookie.setDomain(cookieDomain);
        redditSessionCookie.setPath(cookiePath);
        if (cookieExpiryDate != -1)
            redditSessionCookie.setExpiryDate(new Date(cookieExpiryDate));
        else
            redditSessionCookie.setExpiryDate(null);
        this.setRedditSessionCookie(redditSessionCookie);
        RedditIsFunHttpClientFactory.getCookieStore().addCookie(redditSessionCookie);
        try {
            CookieSyncManager.getInstance().sync();
        } catch (IllegalStateException ex) {
            if (Constants.LOGGING)
                Log.e(TAG, "CookieSyncManager.getInstance().sync()", ex);
        }
    }

    // Default subreddit
    String homepage = sessionPrefs.getString(Constants.PREF_HOMEPAGE, Constants.FRONTPAGE_STRING).trim();
    if (StringUtils.isEmpty(homepage))
        this.setHomepage(Constants.FRONTPAGE_STRING);
    else
        this.setHomepage(homepage);

    // Use external browser instead of BrowserActivity
    this.setUseExternalBrowser(sessionPrefs.getBoolean(Constants.PREF_USE_EXTERNAL_BROWSER, false));

    // Show confirmation dialog when backing out of root Activity
    this.setConfirmQuitOrLogout(sessionPrefs.getBoolean(Constants.PREF_CONFIRM_QUIT, true));

    // Save reddit history to Browser history
    this.setSaveHistory(sessionPrefs.getBoolean(Constants.PREF_SAVE_HISTORY, true));

    // Whether to always show the next/previous buttons, or only at bottom of list
    this.setAlwaysShowNextPrevious(sessionPrefs.getBoolean(Constants.PREF_ALWAYS_SHOW_NEXT_PREVIOUS, true));

    // Comments sort order
    this.setCommentsSortByUrl(sessionPrefs.getString(Constants.PREF_COMMENTS_SORT_BY_URL,
            Constants.CommentsSort.SORT_BY_BEST_URL));

    // Theme and text size
    this.setTheme(Util.getThemeResourceFromPrefs(
            sessionPrefs.getString(Constants.PREF_THEME, Constants.PREF_THEME_LIGHT),
            sessionPrefs.getString(Constants.PREF_TEXT_SIZE, Constants.PREF_TEXT_SIZE_MEDIUM)));

    // Comment guide lines
    this.setShowCommentGuideLines(sessionPrefs.getBoolean(Constants.PREF_SHOW_COMMENT_GUIDE_LINES, true));

    // Rotation
    this.setRotation(RedditSettings.Rotation
            .valueOf(sessionPrefs.getString(Constants.PREF_ROTATION, Constants.PREF_ROTATION_UNSPECIFIED)));

    // Thumbnails
    this.setLoadThumbnails(sessionPrefs.getBoolean(Constants.PREF_LOAD_THUMBNAILS, true));
    // Thumbnails on Wifi
    this.setLoadThumbnailsOnlyWifi(sessionPrefs.getBoolean(Constants.PREF_LOAD_THUMBNAILS_ONLY_WIFI, false));

    // Notifications
    this.setMailNotificationStyle(sessionPrefs.getString(Constants.PREF_MAIL_NOTIFICATION_STYLE,
            Constants.PREF_MAIL_NOTIFICATION_STYLE_DEFAULT));
    this.setMailNotificationService(sessionPrefs.getString(Constants.PREF_MAIL_NOTIFICATION_SERVICE,
            Constants.PREF_MAIL_NOTIFICATION_SERVICE_OFF));
}

From source file:at.ac.uniklu.mobile.sportal.WebViewActivity.java

@SuppressLint("SetJavaScriptEnabled")
@Override//www  .ja v a 2  s .co m
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    String targetUrl = getIntent().getStringExtra(URL);
    if (targetUrl == null || targetUrl.length() == 0) {
        // if there's no URL, close the activity
        finish();
    }

    setContentView(R.layout.webview);
    mActionBar = new ActionBarHelper(this).setupHeader().addActionRefresh();

    // set header title or hide header if no title is given
    String title = getIntent().getStringExtra(TITLE);
    if (title != null) {
        ((TextView) findViewById(R.id.view_title)).setText(title);
    } else {
        findViewById(R.id.actionbar).setVisibility(View.GONE);
    }

    // Moodle 2.0 uses SSO/CAS authentication
    mSSO = getIntent().getBooleanExtra(SSO, false);

    // the moodle hack is only needed until Android 2.3 (or maybe 3.x? - not tested)
    // Android 4.0 has the redirect history entry problem solved
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
        mExecuteMoodleHack = getIntent().getBooleanExtra(MOODLE_HACK, false);
    }

    mWebView = (WebView) findViewById(R.id.web_view);
    //mWebView.setBackgroundColor(Color.BLACK); // black color messes up the CAS login page
    mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); // http://stackoverflow.com/questions/3998916/android-webview-leaves-space-for-scrollbar
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setLightTouchEnabled(true);
    mWebView.getSettings().setLoadWithOverviewMode(true);
    mWebView.getSettings().setBuiltInZoomControls(true);
    mWebView.getSettings().setUseWideViewPort(true);

    // setup custom webview client that shows a progress dialog while loading
    mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.startsWith("https://sso.uni-klu.ac.at") || url.startsWith("https://sso.aau.at")
                    || url.startsWith("https://campus.aau.at") || url.startsWith("https://moodle.aau.at")) {
                return false;
            } else if (url.startsWith("http://campus-gis.aau.at/")) {
                Log.d(TAG, "REDIRECT TO MAP");
                String roomParameter = "curRouteTo=";
                int index = url.indexOf(roomParameter);
                if (index > -1) {
                    MapUtils.openMapAndShowRoom(WebViewActivity.this,
                            url.substring(index + roomParameter.length()));
                }
                return true;
            }

            // open external websites in browser
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(url));
            startActivity(i);
            return true;
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            progressNotificationOn();
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            super.onReceivedError(view, errorCode, description, failingUrl);
            progressNotificationOff();
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            progressNotificationOff();

            /*
             *  the first page of moodle opens through a redirect so we need to clear the first history
             *  entry to avoid execution of the redirect when going back through the history with the back button
             */
            if (mExecuteMoodleHack && mWebView.canGoBack()) {
                mWebView.clearHistory();
                mExecuteMoodleHack = false;
            } else {
                mIsFirstPage = false;
            }
        }
    });

    mWebView.setDownloadListener(new DownloadListener() {
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype,
                long contentLength) {
            Analytics.onEvent(Analytics.EVENT_WEB_COURSEMOODLE_DOWNLOAD);
            Uri uri = Uri.parse(url);
            MoodleDownloadHelper.download(WebViewActivity.this, uri,
                    Utils.getContentDispositionOrUrlFilename(contentDisposition, uri));
        }
    });

    // set session cookie
    // http://stackoverflow.com/questions/1652850/android-webview-cookie-problem
    // http://android.joao.jp/2010/11/cookiemanager-and-removeallcookie.html
    if (Studentportal.getSportalClient().isSessionCookieAvailable()) {
        CookieSyncManager.createInstance(this);
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.setAcceptCookie(true);
        //cookieManager.removeSessionCookie(); // NOTE when calling this method the cookies get removed after the next setCookie() gets called

        Cookie sessionCookie = Studentportal.getSportalClient().getSessionCookie();
        cookieManager.setCookie(sessionCookie.getDomain(), Utils.cookieHeaderString(sessionCookie));

        if (mSSO) {
            // set SSO/CAS cookie
            Cookie ssoCookie = Studentportal.getSportalClient().getCookie("CASTGC");
            if (ssoCookie != null) {
                cookieManager.setCookie(ssoCookie.getDomain(), Utils.cookieHeaderString(ssoCookie));
            }
        }

        CookieSyncManager.getInstance().sync();
    }

    mIsFirstPage = true;
    mWebView.loadUrl(targetUrl);
}

From source file:org.zywx.wbpalmstar.widgetone.WidgetOneApplication.java

public final void exitApp() {
    stopAnalyticsAgent();
    CookieSyncManager.getInstance().stopSync();
}

From source file:com.microsoft.aad.adal.hello.MainActivity.java

private void clearSessionCookie() {
    // Webview by default does not clear session cookies even after app is
    // closed(Bug in Webview).
    // Example to clean session cookie
    Logger.v(TAG, "Clear session cookies");
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeSessionCookie();
    CookieSyncManager.getInstance().sync();
}

From source file:net.granoeste.scaffold.app.ScaffoldWebViewFragment.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override/*  www.j  a va  2  s . c  o m*/
public void onPause() {
    super.onPause();
    if (UIUtils.hasHoneycomb()) {
        mWebView.onPause();
    }
    // Pauses all layout, parsing, and JavaScript timers for all WebViews.
    mWebView.pauseTimers();

    // TPS: Cookie?????????????onPause???
    //      // Requests sync manager to stop sync.
    //        CookieSyncManager.getInstance().stopSync();
    // Cookie?
    CookieSyncManager.getInstance().sync();
}

From source file:android.webkit.cts.WebViewTest.java

@UiThreadTest
public void testCreatingWebViewCreatesCookieSyncManager() throws Exception {
    if (!NullWebViewUtils.isWebViewAvailable()) {
        return;/*  ww  w .j a  va2  s.co  m*/
    }
    new WebView(getActivity());
    assertNotNull(CookieSyncManager.getInstance());
}

From source file:in.shick.diode.settings.RedditSettings.java

public void loadRedditPreferences(Context context, HttpClient client) {
    // Session//from   ww  w .  ja v a  2  s.  co  m
    SharedPreferences sessionPrefs = PreferenceManager.getDefaultSharedPreferences(context);
    this.setUsername(sessionPrefs.getString("username", null));
    this.setModhash(sessionPrefs.getString("modhash", null));
    String cookieValue = sessionPrefs.getString("reddit_sessionValue", null);
    String cookieDomain = sessionPrefs.getString("reddit_sessionDomain", null);
    String cookiePath = sessionPrefs.getString("reddit_sessionPath", null);
    long cookieExpiryDate = sessionPrefs.getLong("reddit_sessionExpiryDate", -1);
    if (cookieValue != null) {
        BasicClientCookie redditSessionCookie = new BasicClientCookie("reddit_session", cookieValue);
        redditSessionCookie.setDomain(cookieDomain);
        redditSessionCookie.setPath(cookiePath);
        if (cookieExpiryDate != -1)
            redditSessionCookie.setExpiryDate(new Date(cookieExpiryDate));
        else
            redditSessionCookie.setExpiryDate(null);
        this.setRedditSessionCookie(redditSessionCookie);
        RedditIsFunHttpClientFactory.getCookieStore().addCookie(redditSessionCookie);
        try {
            CookieSyncManager.getInstance().sync();
        } catch (IllegalStateException ex) {
            if (Constants.LOGGING)
                Log.e(TAG, "CookieSyncManager.getInstance().sync()", ex);
        }
    }

    // Default subreddit
    String homepage = sessionPrefs.getString(Constants.PREF_HOMEPAGE, Constants.FRONTPAGE_STRING).trim();
    if (StringUtils.isEmpty(homepage))
        this.setHomepage(Constants.FRONTPAGE_STRING);
    else
        this.setHomepage(homepage);

    //Browser Settings
    this.setOverwriteUA(sessionPrefs.getBoolean(Constants.PREF_OVERWRITE_UA, false));
    this.setUseragent(sessionPrefs.getString(Constants.BROWSER_UA, Constants.BROWSER_UA_STRING));
    this.setLoadJS(sessionPrefs.getBoolean(Constants.PREF_LOAD_JS, true));
    this.setLoadPlugins(sessionPrefs.getBoolean(Constants.PREF_LOAD_PLUGINS, true));
    this.setLoadImgurImagesDirectly(sessionPrefs.getBoolean(Constants.PREF_IMGUR_DIRECT, true));
    this.setLoadVredditLinksDirectly(sessionPrefs.getBoolean(Constants.PREF_VREDDIT_DIRECT, false));

    // Use external browser instead of BrowserActivity
    this.setUseExternalBrowser(sessionPrefs.getBoolean(Constants.PREF_USE_EXTERNAL_BROWSER, false));

    // Show confirmation dialog when backing out of root Activity
    this.setConfirmQuitOrLogout(sessionPrefs.getBoolean(Constants.PREF_CONFIRM_QUIT, true));

    // Save reddit history to Browser history
    this.setSaveHistory(sessionPrefs.getBoolean(Constants.PREF_SAVE_HISTORY, true));

    // Whether to always show the next/previous buttons, or only at bottom of list
    this.setAlwaysShowNextPrevious(sessionPrefs.getBoolean(Constants.PREF_ALWAYS_SHOW_NEXT_PREVIOUS, true));

    // Comments sort order
    this.setCommentsSortByUrl(sessionPrefs.getString(Constants.PREF_COMMENTS_SORT_BY_URL,
            Constants.CommentsSort.SORT_BY_BEST_URL));

    // Theme and text size
    this.setTheme(Util.getThemeResourceFromPrefs(
            sessionPrefs.getString(Constants.PREF_THEME, Constants.PREF_THEME_LIGHT),
            sessionPrefs.getString(Constants.PREF_TEXT_SIZE, Constants.PREF_TEXT_SIZE_MEDIUM)));

    // Comment guide lines
    this.setShowCommentGuideLines(sessionPrefs.getBoolean(Constants.PREF_SHOW_COMMENT_GUIDE_LINES, true));

    // Rotation
    this.setRotation(RedditSettings.Rotation
            .valueOf(sessionPrefs.getString(Constants.PREF_ROTATION, Constants.PREF_ROTATION_UNSPECIFIED)));

    // Thumbnails
    this.setLoadThumbnails(sessionPrefs.getBoolean(Constants.PREF_LOAD_THUMBNAILS, true));
    // Thumbnails on Wifi
    this.setLoadThumbnailsOnlyWifi(sessionPrefs.getBoolean(Constants.PREF_LOAD_THUMBNAILS_ONLY_WIFI, false));

    // NSFW
    this.setShowNSFW(sessionPrefs.getBoolean(Constants.PREF_SHOW_NSFW, Constants.PREF_SHOW_NSFW_DEFAULT));
    // Notifications
    this.setMailNotificationStyle(sessionPrefs.getString(Constants.PREF_MAIL_NOTIFICATION_STYLE,
            Constants.PREF_MAIL_NOTIFICATION_STYLE_DEFAULT));
    this.setMailNotificationService(sessionPrefs.getString(Constants.PREF_MAIL_NOTIFICATION_SERVICE,
            Constants.PREF_MAIL_NOTIFICATION_SERVICE_OFF));
    this.setFilters(sessionPrefs.getString(Constants.PREF_REDDIT_FILTERS, null));

}

From source file:net.granoeste.scaffold.app.ScaffoldWebViewFragment.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override/*w  w w .  j  a v  a2 s  . co  m*/
public void onResume() {
    super.onResume();
    if (UIUtils.hasHoneycomb()) {
        mWebView.onResume();
    }
    // Resumes all layout, parsing, and JavaScript timers for all WebViews.
    mWebView.resumeTimers();

    // TPS: Cookie?????????????onPause???
    //      // Requests sync manager to start sync
    //        CookieSyncManager.getInstance().startSync();
    // Cookie???
    CookieSyncManager.getInstance().stopSync();
}