Example usage for java.net CookieHandler getDefault

List of usage examples for java.net CookieHandler getDefault

Introduction

In this page you can find the example usage for java.net CookieHandler getDefault.

Prototype

public static synchronized CookieHandler getDefault() 

Source Link

Document

Gets the system-wide cookie handler.

Usage

From source file:com.studyjams.mdvideo.PlayerModule.PlayerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.player_activity);
    View root = findViewById(R.id.root);
    root.setOnTouchListener(new OnTouchListener() {
        @Override//from  ww  w .j av a  2s.com
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
                toggleControlsVisibility();
            } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
                view.performClick();
            }
            return true;
        }
    });
    root.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE
                    || keyCode == KeyEvent.KEYCODE_MENU) {
                return false;
            }
            return mediaController.dispatchKeyEvent(event);
        }
    });

    shutterView = findViewById(R.id.shutter);
    //        debugRootView = findViewById(R.id.controls_root);

    videoFrame = (AspectRatioFrameLayout) findViewById(R.id.video_frame);
    surfaceView = (SurfaceView) findViewById(R.id.surface_view);
    surfaceView.getHolder().addCallback(this);
    //        debugTextView = (TextView) findViewById(R.id.debug_text_view);

    //        playerStateTextView = (TextView) findViewById(R.id.player_state_view);
    subtitleLayout = (SubtitleLayout) findViewById(R.id.subtitles);

    mediaController = new ExtractorMediaController(this);
    mediaController.setAnchorView(root);
    //        retryButton = (Button) findViewById(R.id.retry_button);
    //        retryButton.setOnClickListener(this);
    //        videoButton = (Button) findViewById(R.id.video_controls);
    //        audioButton = (Button) findViewById(R.id.audio_controls);
    //        textButton = (Button) findViewById(R.id.text_controls);

    //?mediaController??window
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    CookieHandler currentHandler = CookieHandler.getDefault();
    if (currentHandler != defaultCookieManager) {
        CookieHandler.setDefault(defaultCookieManager);
    }

    audioCapabilitiesReceiver = new AudioCapabilitiesReceiver(this, this);
    audioCapabilitiesReceiver.register();
}

From source file:im.ene.toro.exoplayer2.ExoVideoView.java

public ExoVideoView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    // By default, TextureView is used for Android 23 and below, and SurfaceView is for the rest
    boolean useTextureView = context.getResources().getBoolean(R.bool.use_texture_view);
    if (attrs != null) {
        TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ExoVideoView, 0, 0);
        try {/*from  w  w w  . j a  v  a2s. co m*/
            int surfaceType = a.getInt(R.styleable.ExoVideoView_tx2_surfaceType, SURFACE_TYPE_DEFAULT);
            switch (surfaceType) {
            case SURFACE_TYPE_SURFACE_VIEW:
                useTextureView = false;
                break;
            case SURFACE_TYPE_TEXTURE_VIEW:
                useTextureView = true;
                break;
            case SURFACE_TYPE_DEFAULT:
            default:
                // Unchanged, so don't need to execute the line below
                // useTextureView = context.getResources().getBoolean(R.bool.use_texture_view);
                break;
            }

            resizeMode = a.getInt(R.styleable.ExoVideoView_tx2_resizeMode, RESIZE_MODE_FIXED_WIDTH);
        } finally {
            a.recycle();
        }
    }

    View view = useTextureView ? new TextureView(context) : new SurfaceView(context);
    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    view.setLayoutParams(params);
    surfaceView = view;
    addView(surfaceView, 0);

    shutterView = new View(context);
    ViewGroup.LayoutParams shutterViewParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    shutterView.setLayoutParams(shutterViewParams);
    shutterView.setBackgroundColor(Color.BLACK);
    addView(shutterView);

    window = new Timeline.Window();

    componentListener = new ComponentListener();

    mediaDataSourceFactory = buildDataSourceFactory(true);
    mainHandler = new Handler();

    if (CookieHandler.getDefault() != DEFAULT_COOKIE_MANAGER) {
        CookieHandler.setDefault(DEFAULT_COOKIE_MANAGER);
    }

    requestFocus();
}

From source file:io.jari.geenstijl.API.API.java

/**
 * ensureCookies sets up cookiemanager and makes sure cookies are set up
 *//* w ww  .ja v a  2s.  c o m*/
static void ensureCookies() {
    if (CookieHandler.getDefault() == null) {
        cookieManager = new CookieManager(null, CookiePolicy.ACCEPT_ALL);
        CookieHandler.setDefault(cookieManager);
    }
}

From source file:org.horaapps.leafpic.activities.PlayerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(org.horaapps.leafpic.R.layout.activity_player);

    FrameLayout root = (FrameLayout) findViewById(org.horaapps.leafpic.R.id.root);
    findViewById(R.id.video_frame).setOnClickListener(new View.OnClickListener() {
        @Override/*from  w  w  w . j a v  a2  s .  c om*/
        public void onClick(View view) {
            toggleControlsVisibility();
        }
    });

    root.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            return !(keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE
                    || keyCode == KeyEvent.KEYCODE_MENU) && mediaController.dispatchKeyEvent(event);
        }
    });

    root.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.md_black_1000));

    shutterView = findViewById(org.horaapps.leafpic.R.id.shutter);

    videoFrame = (AspectRatioFrameLayout) findViewById(org.horaapps.leafpic.R.id.video_frame);
    surfaceView = (SurfaceView) findViewById(org.horaapps.leafpic.R.id.surface_view);
    surfaceView.getHolder().addCallback(this);

    mediaController = new CustomMediaController(this, this);

    mediController_anchor = findViewById(org.horaapps.leafpic.R.id.media_player_anchor);
    mediaController.setAnchorView(root);
    //mediaController.setPaddingRelative(0,0,0,Measure.getNavBarHeight(PlayerActivity.this));
    toolbar = (Toolbar) findViewById(org.horaapps.leafpic.R.id.toolbar);
    initUI();

    CookieHandler currentHandler = CookieHandler.getDefault();
    if (currentHandler != defaultCookieManager)
        CookieHandler.setDefault(defaultCookieManager);

    audioCapabilitiesReceiver = new AudioCapabilitiesReceiver(this, this);
    audioCapabilitiesReceiver.register();
}

From source file:com.google.android.exoplayer2.demo.MediaPlayerFragment.java

@Override
public void onViewCreated(View v, Bundle savedInstanceState) {
    //@Override/* w  w w  . j av a  2  s .  com*/
    //public void onCreate(Bundle savedInstanceState) {
    super.onViewCreated(v, savedInstanceState);

    shouldAutoPlay = true;
    clearResumePosition();
    mediaDataSourceFactory = buildDataSourceFactory(true);
    mainHandler = new Handler();
    if (CookieHandler.getDefault() != DEFAULT_COOKIE_MANAGER) {
        CookieHandler.setDefault(DEFAULT_COOKIE_MANAGER);
    }

    //setContentView(R.layout.player_activity);
    View rootView = v.findViewById(R.id.root);
    rootView.setOnClickListener(this);
    debugRootView = (LinearLayout) v.findViewById(R.id.controls_root);
    debugTextView = (TextView) v.findViewById(R.id.debug_text_view);
    retryButton = (Button) v.findViewById(R.id.retry_button);
    retryButton.setOnClickListener(this);
    centerInfo = (TextView) v.findViewById(R.id.centerInfo);
    //        localTime = (TextView) v.findViewById(R.id.localTime);
    //        battery = (BatteryLevelView) v.findViewById(R.id.battery);

    simpleExoPlayerView = (SimpleExoPlayerView) v.findViewById(R.id.player_view);
    simpleExoPlayerView.setControllerVisibilityListener(this);
    simpleExoPlayerView.requestFocus();

    final Intent intent = getActivity().getIntent();
    if (intent != null) {
        Uri extras = intent.getData();
        if (extras != null) {
            CURRENT_PATH = extras.getPath();
            Log.d(TAG, "intent.getData() " + CURRENT_PATH);
        }
    }
    updateColor(rootView);
}

From source file:com.hybris.mobile.Hybris.java

public static void clearCookies() {
    CookieManager cookieManager = (CookieManager) CookieHandler.getDefault();
    cookieManager.getCookieStore().removeAll();
}

From source file:org.fossasia.phimpme.leafpic.activities.PlayerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_player);

    FrameLayout root = (FrameLayout) findViewById(R.id.root);
    findViewById(R.id.video_frame).setOnClickListener(new View.OnClickListener() {
        @Override/*from  www . java2 s .  c om*/
        public void onClick(View view) {
            toggleControlsVisibility();
        }
    });

    root.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            return !(keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE
                    || keyCode == KeyEvent.KEYCODE_MENU) && mediaController.dispatchKeyEvent(event);
        }
    });

    root.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.md_black_1000));

    shutterView = findViewById(R.id.shutter);

    videoFrame = (AspectRatioFrameLayout) findViewById(R.id.video_frame);
    surfaceView = (SurfaceView) findViewById(R.id.surface_view);
    surfaceView.getHolder().addCallback(this);

    mediaController = new CustomMediaController(this, this);

    mediController_anchor = findViewById(R.id.media_player_anchor);
    mediaController.setAnchorView(root);
    //mediaController.setPaddingRelative(0,0,0,Measure.getNavBarHeight(PlayerActivity.this));
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    initUI();

    CookieHandler currentHandler = CookieHandler.getDefault();
    if (currentHandler != defaultCookieManager)
        CookieHandler.setDefault(defaultCookieManager);

    audioCapabilitiesReceiver = new AudioCapabilitiesReceiver(this, this);
    audioCapabilitiesReceiver.register();
}

From source file:com.horaapps.leafpic.PlayerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_player);

    FrameLayout root = (FrameLayout) findViewById(R.id.root);
    root.setOnTouchListener(new OnTouchListener() {
        @Override/* w w  w  .  j  a  v  a 2s .  co m*/
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
                toggleControlsVisibility();
            } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
                //view.performClick();
            }
            return true;
        }
    });

    root.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            return !(keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE
                    || keyCode == KeyEvent.KEYCODE_MENU) && mediaController.dispatchKeyEvent(event);
        }
    });

    root.setBackgroundColor(R.color.md_black_1000);

    shutterView = findViewById(R.id.shutter);

    videoFrame = (AspectRatioFrameLayout) findViewById(R.id.video_frame);
    surfaceView = (SurfaceView) findViewById(R.id.surface_view);
    surfaceView.getHolder().addCallback(this);

    mediaController = new KeyCompatibleMediaController(this);

    mediController_anchor = findViewById(R.id.media_player_anchor);
    mediaController.setAnchorView(mediController_anchor);
    mediaController.setPaddingRelative(0, 0, 0, Measure.getNavBarHeight(PlayerActivity.this));
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    initUI();

    CookieHandler currentHandler = CookieHandler.getDefault();
    if (currentHandler != defaultCookieManager)
        CookieHandler.setDefault(defaultCookieManager);

    audioCapabilitiesReceiver = new AudioCapabilitiesReceiver(this, this);
    audioCapabilitiesReceiver.register();
}

From source file:no.eris.applet.AppletViewer.java

private void overrideCookieHandler(CookieManager manager) {
    manager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    final CookieHandler handler = CookieHandler.getDefault();

    LOGGER.debug("CookieStore: size {}", manager.getCookieStore().getCookies().size());
    if (cookies != null) {
        for (UriAndCookie uriAndCookie : cookies) {
            URI uri = uriAndCookie.getUri();
            HttpCookie cookie = uriAndCookie.getCookie();
            LOGGER.debug("Adding cookies: <{}> value={} secure={}",
                    new Object[] { uri, cookie, cookie.getSecure() });
            manager.getCookieStore().add(uri, cookie);
        }/*from w  w w  .j  ava2 s.  co  m*/
    }
    LOGGER.debug("CookieStore: size {}", manager.getCookieStore().getCookies().size());
    LOGGER.debug("Overriding cookie handler: {}", (handler == null ? null : handler.getClass().getName()));
    // FIXME because we depend on the system-wide cookie manager, we probably cannot run multiple applets at the time
    // we also maybe have some security issues lurking here...
    // I could maybe partition the callers based on the ThreadGroup ?? 
    // FIXME theres also some cleanup to do somewhere
    CookieHandler.setDefault(new LoggingCookieHandler(manager));
}

From source file:com.blackducksoftware.integration.hub.rest.RestConnection.java

public void handleRequest(final ClientResource resource) throws BDRestException {
    final boolean debugLogging = isDebugLogging();
    if (debugLogging) {
        logMessage(LogLevel.TRACE, "Resource : " + resource.toString());
        logRestletRequestOrResponse(resource.getRequest());
    }// w  ww.  j a  v a2s .  c om

    final CookieHandler originalCookieHandler = CookieHandler.getDefault();
    try {
        if (originalCookieHandler != null) {
            if (debugLogging) {
                logMessage(LogLevel.TRACE, "Setting Cookie Handler to NULL");
            }
            CookieHandler.setDefault(null);
        }
        resource.handle();
    } catch (final ResourceException e) {
        throw new BDRestException("Problem connecting to the Hub server provided.", e, resource);
    } finally {
        if (originalCookieHandler != null) {
            if (debugLogging) {
                logMessage(LogLevel.TRACE,
                        "Setting Original Cookie Handler : " + originalCookieHandler.toString());
            }
            CookieHandler.setDefault(originalCookieHandler);
        }
    }

    if (debugLogging) {
        logRestletRequestOrResponse(resource.getResponse());
        logMessage(LogLevel.TRACE, "Status Code : " + resource.getResponse().getStatus().getCode());
    }
}