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:ti.modules.titanium.network.NetworkModule.java

/**
 * Removes the cookie with the domain, path and name exactly the same as the given values.
 * @param domain the domain of the cookie to remove. It is case-insensitive.
 * @param path the path of the cookie to remove. It is case-sensitive.
 * @param name the name of the cookie to remove. It is case-sensitive.
 *//*from   w  w w . ja v a  2 s. c o  m*/
@Kroll.method
public void removeSystemCookie(String domain, String path, String name) {
    if (domain == null || name == null) {
        if (Log.isDebugModeEnabled()) {
            Log.e(TAG, "Unable to remove the system cookie. Need to provide a valid domain / name.");
        }
        return;
    }
    String lower_domain = domain.toLowerCase();
    String cookieString = name + "=; domain=" + lower_domain + "; path=" + path + "; expires="
            + CookieProxy.systemExpiryDateFormatter.format(new Date(0));
    CookieSyncManager.createInstance(TiApplication.getInstance().getRootOrCurrentActivity());
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.setCookie(lower_domain, cookieString);
    CookieSyncManager.getInstance().sync();
}

From source file:ti.modules.titanium.network.NetworkModule.java

/**
 * Removes all the cookies in the system cookie store.
 *///from w  w w.  ja  v  a 2  s  .  c  o  m
@Kroll.method
public void removeAllSystemCookies() {
    CookieSyncManager.createInstance(TiApplication.getInstance().getRootOrCurrentActivity());
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();
    CookieSyncManager.getInstance().sync();
}

From source file:net.olejon.spotcommander.WebViewActivity.java

@Override
public void onPause() {
    super.onPause();

    mActivityIsPaused = true;//from   w w w .  java2s .  com

    if (mWakeLock.isHeld())
        mWakeLock.release();

    if (!mHasLongPressedBack) {
        final String nowplaying_artist = mTools.getSharedPreferencesString("NOWPLAYING_ARTIST");
        final String nowplaying_title = mTools.getSharedPreferencesString("NOWPLAYING_TITLE");

        if (!nowplaying_artist.equals(getString(R.string.notification_no_music_is_playing_artist))) {
            if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
                Wearable.NodeApi.getConnectedNodes(mGoogleApiClient)
                        .setResultCallback(new ResultCallback<NodeApi.GetConnectedNodesResult>() {
                            @Override
                            public void onResult(
                                    @NonNull NodeApi.GetConnectedNodesResult getConnectedNodesResult) {
                                mNotificationBuilder.setWhen(0)
                                        .setSmallIcon(R.drawable.ic_play_arrow_white_24dp)
                                        .setLargeIcon(BitmapFactory.decodeResource(getResources(),
                                                R.mipmap.ic_launcher))
                                        .setContentTitle(getString(R.string.project_name))
                                        .setContentIntent(mLaunchActivityPendingIntent)
                                        .setTicker(nowplaying_artist + " - " + nowplaying_title)
                                        .extend(new NotificationCompat.WearableExtender().setHintHideIcon(true)
                                                .setBackground(BitmapFactory.decodeResource(getResources(),
                                                        R.drawable.notification_background))
                                                .addAction(new NotificationCompat.Action.Builder(
                                                        R.drawable.notification_icon,
                                                        getString(R.string.notification_action_play_pause),
                                                        mPlayPausePendingIntent).build())
                                                .addAction(new NotificationCompat.Action.Builder(
                                                        R.drawable.ic_skip_next_white_24dp,
                                                        getString(R.string.notification_action_next),
                                                        mNextPendingIntent).build())
                                                .addAction(new NotificationCompat.Action.Builder(
                                                        R.drawable.ic_volume_down_white_24dp,
                                                        getString(R.string.notification_action_volume_down),
                                                        mVolumeDownPendingIntent).build())
                                                .addAction(new NotificationCompat.Action.Builder(
                                                        R.drawable.ic_volume_up_white_24dp,
                                                        getString(R.string.notification_action_volume_up),
                                                        mVolumeUpPendingIntent).build())
                                                .setContentIcon(R.drawable.notification_icon)
                                                .setContentAction(0));

                                if (getConnectedNodesResult.getNodes().size() > 0) {
                                    mNotificationBuilder
                                            .setContentText(getString(R.string.notification_wear_text))
                                            .addAction(R.drawable.ic_skip_previous_white_24dp,
                                                    getString(R.string.notification_action_previous),
                                                    mPreviousPendingIntent)
                                            .addAction(R.drawable.ic_play_arrow_white_24dp,
                                                    getString(R.string.notification_action_play_pause),
                                                    mPlayPausePendingIntent)
                                            .addAction(R.drawable.ic_skip_next_white_24dp,
                                                    getString(R.string.notification_action_next),
                                                    mNextPendingIntent);

                                    mNotificationManager.notify(NOTIFICATION_ID, mNotificationBuilder.build());
                                } else if (mPersistentNotificationIsSupported
                                        && mTools.getSharedPreferencesBoolean("PERSISTENT_NOTIFICATION")) {
                                    mNotificationBuilder.setOngoing(true)
                                            .setContentText(getString(R.string.notification_mobile_text))
                                            .addAction(R.drawable.ic_close_white_24dp,
                                                    getString(R.string.notification_action_hide),
                                                    mHidePendingIntent)
                                            .addAction(R.drawable.ic_play_arrow_white_24dp,
                                                    getString(R.string.notification_action_play_pause),
                                                    mPlayPausePendingIntent)
                                            .addAction(R.drawable.ic_skip_next_white_24dp,
                                                    getString(R.string.notification_action_next),
                                                    mNextPendingIntent);

                                    mNotificationManager.notify(NOTIFICATION_ID, mNotificationBuilder.build());
                                }
                            }
                        });
            } else if (mPersistentNotificationIsSupported
                    && mTools.getSharedPreferencesBoolean("PERSISTENT_NOTIFICATION")) {
                mNotificationBuilder.setWhen(0).setOngoing(true)
                        .setSmallIcon(R.drawable.ic_play_arrow_white_24dp)
                        .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
                        .setContentTitle(getString(R.string.project_name))
                        .setContentText(getString(R.string.notification_mobile_text))
                        .setContentIntent(mLaunchActivityPendingIntent)
                        .setTicker(nowplaying_artist + " - " + nowplaying_title)
                        .addAction(R.drawable.ic_close_white_24dp, getString(R.string.notification_action_hide),
                                mHidePendingIntent)
                        .addAction(R.drawable.ic_play_arrow_white_24dp,
                                getString(R.string.notification_action_play_pause), mPlayPausePendingIntent)
                        .addAction(R.drawable.ic_skip_next_white_24dp,
                                getString(R.string.notification_action_next), mNextPendingIntent);

                mNotificationManager.notify(NOTIFICATION_ID, mNotificationBuilder.build());
            }
        }
    }

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        //noinspection deprecation
        CookieSyncManager.getInstance().sync();
    }

    mWebView.pauseTimers();
}

From source file:com.example.office.ui.Office365DemoActivity.java

/**
 * Clears cookies used for AADAL authentication.
 *///from  w  w w.j a va2s.c o  m
private void clearCookies() {
    CookieSyncManager.createInstance(getApplicationContext());
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();
    CookieSyncManager.getInstance().sync();
}

From source file:jmri.enginedriver.throttle.java

@Override
public void onResume() {
    super.onResume();
    mainapp.removeNotification();/*from   www .  j av  a 2  s . c om*/
    if (mainapp.isForcingFinish()) { // expedite
        mainapp.appIsFinishing = true;
        this.finish();
        overridePendingTransition(0, 0);
        return;
    }
    if (!mainapp.setActivityOrientation(this)) // set screen orientation based on prefs
    {
        Intent in = new Intent().setClass(this, web_activity.class); // if autoWeb and landscape, switch to Web activity
        in.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        navigatingAway = true;
        startActivity(in);
        connection_activity.overridePendingTransition(this, R.anim.fade_in, R.anim.fade_out);
        return;
    }
    navigatingAway = false;
    currentTime = "";
    mainapp.sendMsg(mainapp.comm_msg_handler, message_type.CURRENT_TIME); // request time update

    // format the screen area
    for (int throttleIndex = 0; throttleIndex < mainapp.maxThrottles; throttleIndex++) {
        enable_disable_buttons(throttleIndex);
    }

    gestureFailed = false;
    gestureInProgress = false;

    getCommonPrefs(false);
    getDirectionButtonPrefs();
    setThottleNumLimits();

    clearVolumeAndGamepadAdditionalIndicators();

    getDirectionButtonPrefs();
    setDirectionButtonLabels(); // set all the direction button labels

    setGamepadKeys();

    applySpeedRelatedOptions(); // update all throttles

    set_labels(); // handle labels and update view

    noUrl = getApplicationContext().getResources().getString(R.string.about_page_url);

    if (webView != null) {
        if (!callHiddenWebViewOnResume()) {
            webView.resumeTimers();
        }
        if (noUrl.equals(webView.getUrl()) && webView.canGoBack()) { //unload static url loaded by onPause
            webView.goBack();
        }
    }

    if (mainapp.EStopActivated) {
        speedUpdateAndNotify(0); // update all three throttles
        applySpeedRelatedOptions(); // update all three throttles

        mainapp.EStopActivated = false;
    }

    if (IS_ESU_MCII && isEsuMc2Stopped) {
        if (isEsuMc2AllStopped) {
            // disable buttons for all throttles
            for (int throttleIndex = 0; throttleIndex < mainapp.maxThrottles; throttleIndex++) {
                setEnabledEsuMc2ThrottleScreenButtons(throttleIndex, false);
            }
        } else {
            // disable buttons for current throttle
            setEnabledEsuMc2ThrottleScreenButtons(whichVolume, false);
        }
    }

    // update the direction indicators
    showDirectionIndications();

    if (TMenu != null) {
        for (int throttleIndex = 0; throttleIndex < mainapp.maxThrottles; throttleIndex++) {

            switch (throttleIndex) {
            case 0:
                TMenu.findItem(R.id.EditConsist0_menu).setVisible(mainapp.consists[0].isMulti());
                TMenu.findItem(R.id.EditLightsConsist0_menu).setVisible(mainapp.consists[0].isMulti());
                break;
            case 1:
                TMenu.findItem(R.id.EditLightsConsist1_menu).setVisible(mainapp.consists[1].isMulti());
                TMenu.findItem(R.id.EditConsist1_menu).setVisible(mainapp.consists[1].isMulti());
                break;
            case 2:
                TMenu.findItem(R.id.EditLightsConsist2_menu).setVisible(mainapp.consists[2].isMulti());
                TMenu.findItem(R.id.EditConsist2_menu).setVisible(mainapp.consists[2].isMulti());
                break;
            case 3:
                TMenu.findItem(R.id.EditLightsConsist3_menu).setVisible(mainapp.consists[3].isMulti());
                TMenu.findItem(R.id.EditConsist3_menu).setVisible(mainapp.consists[3].isMulti());
                break;
            case 4:
                TMenu.findItem(R.id.EditLightsConsist4_menu).setVisible(mainapp.consists[4].isMulti());
                TMenu.findItem(R.id.EditConsist4_menu).setVisible(mainapp.consists[4].isMulti());
                break;
            case 5:
                TMenu.findItem(R.id.EditLightsConsist5_menu).setVisible(mainapp.consists[5].isMulti());
                TMenu.findItem(R.id.EditConsist5_menu).setVisible(mainapp.consists[5].isMulti());
                break;
            }
        }
    }

    CookieSyncManager.getInstance().startSync();

    if (!prefAccelerometerShake.equals(ACCELERATOROMETER_SHAKE_NONE)) {
        if (!accelerometerCurrent) { // perference has only just been changed to turn it on
            setupSensor();
        } else {
            sensorManager.registerListener(shakeDetector, accelerometer, SensorManager.SENSOR_DELAY_UI);
        }
    }

    if (((prefKidsTime > 0) && (kidsTimerRunning != KIDS_TIMER_RUNNNING))) {
        mainapp.sendMsg(mainapp.comm_msg_handler, message_type.KIDS_TIMER_ENABLE, "", 0, 0);
    } else {
        if (kidsTimerRunning == KIDS_TIMER_ENDED) {
            mainapp.sendMsg(mainapp.comm_msg_handler, message_type.KIDS_TIMER_END, "", 0, 0);
        }
        if (prefKidsTimer.equals(PREF_KIDS_TIMER_NONE)) {
            kidsTimerActions(KIDS_TIMER_DISABLED, 0);
        }
    }

    setupTts();
}

From source file:jmri.enginedriver.throttle.java

@Override
public void onPause() {
    super.onPause();
    if (webView != null) {
        if (!callHiddenWebViewOnPause()) {
            webView.pauseTimers();//from w ww  .  j  a v  a 2s  .  c  o  m
        }

        String url = webView.getUrl();
        if (url != null && !noUrl.equals(url)) { // if any url has been loaded 
            webView.loadUrl(noUrl); // load a static url to stop any javascript
        }
    }
    CookieSyncManager.getInstance().stopSync();

    if (!this.isFinishing() && !navigatingAway) { // only invoke setContentIntentNotification when going into background
        mainapp.addNotification(this.getIntent());
    }

    if ((isScreenLocked) || (screenDimmed)) {
        isScreenLocked = false;
        screenDimmed = false;
        setScreenBrightness(screenBrightnessOriginal);
        setScreenBrightnessMode(screenBrightnessModeOriginal);
    }

    if (accelerometerCurrent) {
        sensorManager.unregisterListener(shakeDetector);
    }
}

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

public void addCookie(Cookie c, boolean addToWebViewCookieManager, boolean sync) {
    if (addToWebViewCookieManager) {
        CookieManager mgr;/*  ww  w. ja 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);

}

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

public void addCookie(Cookie[] cs, boolean addToWebViewCookieManager, boolean sync) {
    if (addToWebViewCookieManager) {
        CookieManager mgr;// w w w  . j  ava 2  s.  c  o  m
        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"));

        for (Cookie c : cs) {
            String cookieString = c.getName() + "=" + c.getValue() + "; Domain=" + c.getDomain() + "; Path="
                    + c.getPath() + "; " + (c.isSecure() ? "Secure;" : "")
                    + (c.getExpires() != 0 ? (" Expires=" + format.format(new Date(c.getExpires())) + ";") : "")
                    + (c.isHttpOnly() ? "httpOnly;" : "");
            mgr.setCookie("http" + (c.isSecure() ? "s" : "") + "://" + c.getDomain() + c.getPath(),
                    cookieString);

        }

        if (sync) {
            syncer.sync();
        }
    }
    super.addCookie(cs);

}