Example usage for android.webkit CookieSyncManager createInstance

List of usage examples for android.webkit CookieSyncManager createInstance

Introduction

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

Prototype

public static CookieSyncManager createInstance(Context context) 

Source Link

Document

Create a singleton CookieSyncManager within a context

Usage

From source file:com.polyvi.xface.extension.filetransfer.XFileTransferExt.java

/**
 * connectionCookie/*from  ww  w.  ja  v  a2 s . c  o  m*/
 * @param connection   Http
 * @param propert       cookie?
 */
private void setCookieProperty(HttpURLConnection connection, String propert) {
    //Add cookie support
    CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(getContext());
    cookieSyncManager.startSync();
    String cookie = CookieManager.getInstance().getCookie(propert);
    if (cookie != null) {
        connection.setRequestProperty("cookie", cookie);
    }
}

From source file:com.citrus.sdk.CitrusClient.java

/**
 * @param emailId//from w  ww  .ja v a2s  .c o  m
 * @param password
 * @param callback
 */
public synchronized void signIn(final String emailId, final String password,
        final Callback<CitrusResponse> callback) {

    //grant Type username token saved
    retrofitClient.getSignInToken(signinId, signinSecret, emailId, OAuth2GrantType.username.toString(),
            new retrofit.Callback<AccessToken>() {

                @Override
                public void success(AccessToken accessToken, Response response) {
                    if (accessToken.getHeaderAccessToken() != null) {
                        OauthToken token = new OauthToken(mContext, SIGNIN_TOKEN);
                        token.createToken(accessToken.getJSON());///grant Type username token saved

                        retrofitClient.getSignInWithPasswordResponse(signinId, signinSecret, emailId, password,
                                OAuth2GrantType.password.toString(), new retrofit.Callback<AccessToken>() {
                                    @Override
                                    public void success(AccessToken accessToken, Response response) {
                                        Logger.d("SIGN IN RESPONSE " + accessToken.getJSON().toString());
                                        if (accessToken.getHeaderAccessToken() != null) {
                                            OauthToken token = new OauthToken(mContext, PREPAID_TOKEN);
                                            token.createToken(accessToken.getJSON());///grant Type password token saved
                                            token.saveUserDetails(emailId, null);//save email ID of the signed in user

                                            // Activate the user's prepaid account, if not already.
                                            activatePrepaidUser(new Callback<Amount>() {
                                                @Override
                                                public void success(Amount amount) {
                                                    RetroFitClient.setInterCeptor();
                                                    EventBus.getDefault().register(CitrusClient.this);

                                                    retrofitClient.getCookie(emailId, password, "true",
                                                            new retrofit.Callback<String>() {
                                                                @Override
                                                                public void success(String s,
                                                                        Response response) {
                                                                    // NOOP
                                                                    // This method will never be called.
                                                                }

                                                                @Override
                                                                public void failure(RetrofitError error) {
                                                                    if (prepaidCookie != null) {
                                                                        cookieManager = CookieManager
                                                                                .getInstance();
                                                                        PersistentConfig config = new PersistentConfig(
                                                                                mContext);
                                                                        if (config.getCookieString() != null) {
                                                                            cookieManager.getInstance()
                                                                                    .removeSessionCookie();
                                                                        }
                                                                        CookieSyncManager
                                                                                .createInstance(mContext);
                                                                        config.setCookie(prepaidCookie);
                                                                    } else {
                                                                        Logger.d("PREPAID LOGIN UNSUCCESSFUL");
                                                                    }
                                                                    EventBus.getDefault()
                                                                            .unregister(CitrusClient.this);

                                                                    // Since we have a got the cookie, we are giving the callback.
                                                                    sendResponse(callback, new CitrusResponse(
                                                                            ResponseMessages.SUCCESS_MESSAGE_SIGNIN,
                                                                            Status.SUCCESSFUL));
                                                                }
                                                            });
                                                }

                                                @Override
                                                public void error(CitrusError error) {
                                                    sendError(callback, error);
                                                }
                                            });
                                        }
                                    }

                                    @Override
                                    public void failure(RetrofitError error) {
                                        Logger.d("SIGN IN RESPONSE ERROR **" + error.getMessage());
                                        sendError(callback, error);
                                    }
                                });

                    }
                }

                @Override
                public void failure(RetrofitError error) {
                    sendError(callback, error);
                }
            });
}

From source file:com.citrus.sdk.CitrusClient.java

/**
 * Signin with mobile no and password./*from  w  w w .  ja v a 2  s.c  o m*/
 *
 * @param mobileNo
 * @param password
 * @param callback
 */
public synchronized void signInWithMobileNo(final String mobileNo, final String password,
        final Callback<CitrusResponse> callback) {

    //grant Type username token saved
    retrofitClient.getSignInToken(signinId, signinSecret, mobileNo, OAuth2GrantType.username.toString(),
            new retrofit.Callback<AccessToken>() {

                @Override
                public void success(AccessToken accessToken, Response response) {
                    if (accessToken.getHeaderAccessToken() != null) {
                        OauthToken token = new OauthToken(mContext, SIGNIN_TOKEN);
                        token.createToken(accessToken.getJSON());///grant Type username token saved

                        retrofitClient.getSignInWithPasswordResponse(signinId, signinSecret, mobileNo, password,
                                OAuth2GrantType.password.toString(), new retrofit.Callback<AccessToken>() {
                                    @Override
                                    public void success(AccessToken accessToken, Response response) {
                                        Logger.d("SIGN IN RESPONSE " + accessToken.getJSON().toString());
                                        if (accessToken.getHeaderAccessToken() != null) {
                                            final OauthToken token = new OauthToken(mContext, PREPAID_TOKEN);
                                            token.createToken(accessToken.getJSON());///grant Type password token saved

                                            // Fetch the associated emailId and save the emailId.
                                            // This is async since we are just updating the details and not dependent upon the response.
                                            getMemberInfo(null, mobileNo, new Callback<MemberInfo>() {
                                                @Override
                                                public void success(MemberInfo memberInfo) {
                                                    if (memberInfo != null
                                                            && memberInfo.getProfileByMobile() != null) {

                                                        token.saveUserDetails(
                                                                memberInfo.getProfileByMobile().getEmailId(),
                                                                mobileNo);//save email ID of the signed in user
                                                    }
                                                }

                                                @Override
                                                public void error(CitrusError error) {
                                                    // NOOP
                                                    // Do nothing
                                                }
                                            });

                                            // Activate user's prepaid account, if not already.
                                            activatePrepaidUser(new Callback<Amount>() {
                                                @Override
                                                public void success(Amount amount) {
                                                    RetroFitClient.setInterCeptor();
                                                    EventBus.getDefault().register(CitrusClient.this);
                                                    retrofitClient.getCookie(mobileNo, password, "true",
                                                            new retrofit.Callback<String>() {
                                                                @Override
                                                                public void success(String s,
                                                                        Response response) {
                                                                    // NOOP
                                                                    // This method will never be called.
                                                                }

                                                                @Override
                                                                public void failure(RetrofitError error) {
                                                                    if (prepaidCookie != null) {
                                                                        cookieManager = CookieManager
                                                                                .getInstance();
                                                                        PersistentConfig config = new PersistentConfig(
                                                                                mContext);
                                                                        if (config.getCookieString() != null) {
                                                                            cookieManager.getInstance()
                                                                                    .removeSessionCookie();
                                                                        }
                                                                        CookieSyncManager
                                                                                .createInstance(mContext);
                                                                        config.setCookie(prepaidCookie);
                                                                    } else {
                                                                        Logger.d("PREPAID LOGIN UNSUCCESSFUL");
                                                                    }
                                                                    EventBus.getDefault()
                                                                            .unregister(CitrusClient.this);

                                                                    // Since we have a got the cookie, we are giving the callback.
                                                                    sendResponse(callback, new CitrusResponse(
                                                                            ResponseMessages.SUCCESS_MESSAGE_SIGNIN,
                                                                            Status.SUCCESSFUL));
                                                                }
                                                            });
                                                }

                                                @Override
                                                public void error(CitrusError error) {
                                                    sendError(callback, error);
                                                }
                                            });
                                        }
                                    }

                                    @Override
                                    public void failure(RetrofitError error) {
                                        Logger.d("SIGN IN RESPONSE ERROR **" + error.getMessage());
                                        sendError(callback, error);
                                    }
                                });

                    }
                }

                @Override
                public void failure(RetrofitError error) {
                    sendError(callback, error);
                }
            });
}

From source file:com.citrus.sdk.CitrusClient.java

public synchronized void getCookie(String email, String password, final Callback<CitrusResponse> callback) {
    RetroFitClient.setInterCeptor();/*w ww .j  a  v  a  2s . c o  m*/
    EventBus.getDefault().register(CitrusClient.this);
    retrofitClient.getCookie(email, password, "true", new retrofit.Callback<String>() {
        @Override
        public void success(String s, Response response) {
            // NOOP
            // This method will never be called.
        }

        @Override
        public void failure(RetrofitError error) {
            EventBus.getDefault().unregister(CitrusClient.this);

            if (error.getResponse().getStatus() == HttpStatus.SC_INTERNAL_SERVER_ERROR) { //Invalid Password for COOKIE
                CitrusError citrusError = new CitrusError(ResponseMessages.ERROR_MESSAGE_INVALID_PASSWORD,
                        Status.FAILED);
                callback.error(citrusError);
            } else {
                if (prepaidCookie != null) {
                    cookieManager = CookieManager.getInstance();
                    PersistentConfig config = new PersistentConfig(mContext);
                    if (config.getCookieString() != null) {
                        cookieManager.getInstance().removeSessionCookie();
                    }
                    CookieSyncManager.createInstance(mContext);
                    config.setCookie(prepaidCookie);
                } else {
                    Logger.d("PREPAID LOGIN UNSUCCESSFUL");
                }

                // Since we have a got the cookie, we are giving the callback.
                sendResponse(callback,
                        new CitrusResponse(ResponseMessages.SUCCESS_COOKIE_SIGNIN, Status.SUCCESSFUL));
            }
        }
    });
}

From source file:com.dish.browser.activity.BrowserActivity.java

@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
public void clearCookies() {
    // TODO Break out web storage deletion into its own option/action
    // TODO clear web storage for all sites that are visited in Incognito mode
    WebStorage storage = WebStorage.getInstance();
    storage.deleteAllData();/*from w ww.  j  a v a 2  s . c  o m*/
    CookieManager c = CookieManager.getInstance();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        c.removeAllCookies(null);
    } else {
        CookieSyncManager.createInstance(this);
        c.removeAllCookie();
    }
}

From source file:jmri.enginedriver.threaded_application.java

@Override
public void onCreate() {
    super.onCreate();
    Log.d("Engine_Driver", "TA.onCreate()");

    //When starting ED after it has been killed in the bkg, the OS restarts any activities that were running.
    //Since we aren't connected at this point, we want all those activities to finish() so we do 2 things:
    // doFinish=true tells activities (except CA) that aren't running yet to finish() when they reach onResume()
    // DISCONNECT message tells any activities (except CA) that are already running to finish()
    doFinish = true;/*from w  ww.ja  v a2 s .  c  om*/
    port = 0; //indicate that no connection exists
    commThread = new comm_thread();
    commThread.start();
    alert_activities(message_type.DISCONNECT, "");

    /***future Recovery
     //Normally CA is run via the manifest when ED is launched.
     //However when starting ED after it has been killed in the bkg,
     //CA may not be running (or may not be on top).
     //We need to ensure CA is running at this point in the code,
     //so start CA if it is not running else bring to top if already running.
    final Intent caIntent = new Intent(this, connection_activity.class);
    caIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    startActivity(caIntent);
     ***/

    androidVersion = android.os.Build.VERSION.SDK_INT;
    prefs = getSharedPreferences("jmri.enginedriver_preferences", 0);

    function_states_T = new boolean[32];
    function_states_S = new boolean[32];
    function_states_G = new boolean[32];

    dlMetadataTask = new DownloadMetaTask();
    dlRosterTask = new DownloadRosterTask();

    //use worker thread to initialize default function labels from file so UI can continue
    new Thread(new Runnable() {
        public void run() {
            set_default_function_labels();
        }
    }, "DefaultFunctionLabels").start();
    CookieSyncManager.createInstance(this); //create this here so onPause/onResume for webViews can control it
}

From source file:com.codename1.impl.android.AndroidImplementation.java

private static CookieManager getCookieManager() {
    if (android.os.Build.VERSION.SDK_INT >= 21) {
        return CookieManager.getInstance();
    }/* ww w. j a  va 2  s.  co m*/
    if (cookieManager == null) {
        CookieSyncManager.createInstance(getContext()); // Fixes a crash on Android 4.3
        // https://stackoverflow.com/a/20552998/2935174
        cookieManager = CookieManager.getInstance();
    }
    return CookieManager.getInstance();
}

From source file:com.codename1.impl.android.AndroidImplementation.java

public void addCookie(Cookie c, boolean addToWebViewCookieManager, boolean sync) {
    if (addToWebViewCookieManager) {
        CookieManager mgr;//from  w  w  w  .  j a v  a  2 s. com
        CookieSyncManager syncer;
        try {
            syncer = CookieSyncManager.getInstance();
            mgr = getCookieManager();
        } catch (IllegalStateException ex) {
            syncer = CookieSyncManager.createInstance(this.getContext());
            mgr = getCookieManager();
        }
        java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("EEE, dd-MMM-yyyy HH:mm:ss z");
        format.setTimeZone(TimeZone.getTimeZone("GMT"));
        String cookieString = c.getName() + "=" + c.getValue() + "; Domain=" + c.getDomain() + "; Path="
                + c.getPath() + "; " + (c.isSecure() ? "Secure;" : "") + (c.isHttpOnly() ? "httpOnly;" : "")
                + (c.getExpires() != 0 ? ("Expires=" + format.format(new Date(c.getExpires())) + ";") : "");
        mgr.setCookie("http" + (c.isSecure() ? "s" : "") + "://" + c.getDomain() + c.getPath(), cookieString);
        if (sync) {
            syncer.sync();
        }
    }
    super.addCookie(c);

}