// ------------------------------------------------------------------------------------------
  @Override
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register_twitter_account);

    // Find And Initial Views
    webView = (WebView) findViewById(R.id.web_view);

    CookieSyncManager.createInstance(this);
    CookieManager cm = CookieManager.getInstance();
    cm.removeSessionCookie();
    // Web View
    webView.setWebViewClient(
        new WebViewClient() {
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            webView.loadUrl(url);
            return true;
          }
        });
    webView.clearCache(true);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.clearHistory();
    webView.clearFormData();

    pinCode = (TextView) findViewById(R.id.pin_text);

    tableImage = (LinearLayout) findViewById(R.id.tableImage);
    finish = (Button) findViewById(R.id.finish_button);
    number0 = (Button) findViewById(R.id.Button00);
    number1 = (Button) findViewById(R.id.Button01);
    number2 = (Button) findViewById(R.id.Button02);
    number3 = (Button) findViewById(R.id.Button03);
    number4 = (Button) findViewById(R.id.Button04);
    number5 = (Button) findViewById(R.id.Button05);
    number6 = (Button) findViewById(R.id.Button06);
    number7 = (Button) findViewById(R.id.Button07);
    number8 = (Button) findViewById(R.id.Button08);
    number9 = (Button) findViewById(R.id.Button09);
    cancel = (Button) findViewById(R.id.ButtonCancel);

    message = pinCode.getText().toString();

    tableImage.setVisibility(View.GONE);

    // Set Listener
    pinCode.setOnClickListener(this);
    finish.setOnClickListener(this);
    number0.setOnClickListener(this);
    number1.setOnClickListener(this);
    number2.setOnClickListener(this);
    number3.setOnClickListener(this);
    number4.setOnClickListener(this);
    number5.setOnClickListener(this);
    number6.setOnClickListener(this);
    number7.setOnClickListener(this);
    number8.setOnClickListener(this);
    number9.setOnClickListener(this);
    cancel.setOnClickListener(this);
  }
Пример #2
0
 /**
  * Removes cookie by name for a URL.
  *
  * @param url to remove cookie for
  * @param name of the cookie to remove
  */
 public void remove(String url, String name) {
   List<String> domains;
   try {
     domains = getDomainsFromUrl(new URL(url));
   } catch (MalformedURLException e) {
     throw new WebDriverException("Error while adding cookie. " + e);
   }
   for (String domain : domains) {
     List<Cookie> cookies = getCookies(domain);
     for (Cookie c : cookies) {
       if (c.getName().equals(name)) {
         cookies.remove(c);
         // To remove a cookie we set the date somewhere in the past.
         cookieManager.setCookie(
             domain,
             String.format(
                 "%s=; expires=%s",
                 name,
                 new SimpleDateFormat(COOKIE_DATE_FORMAT)
                     .format(System.currentTimeMillis() - 500)));
         break;
       }
     }
   }
   cookieManager.removeExpiredCookie();
 }
Пример #3
0
 public void clearCookie() {
   CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(context);
   CookieManager cookieManager = CookieManager.getInstance();
   cookieManager.setAcceptCookie(true);
   cookieManager.removeSessionCookie(); // cookieManager.removeSessionCookies(null);
   cookieSyncManager.sync(); // cookieManager.flush();
 }
Пример #4
0
  public static void destroy() {
    if (sInstance == null) {
      throw new RuntimeException("No instance to destroy");
    }

    Settings.get().saveData();

    MainApplication app = (MainApplication) sInstance.mContext.getApplicationContext();
    Bus bus = app.getBus();
    bus.unregister(sInstance);

    if (Settings.get().isIncognitoMode()) {
      CookieManager cookieManager = CookieManager.getInstance();
      if (cookieManager != null && cookieManager.hasCookies()) {
        cookieManager.removeAllCookie();
      }
    }

    if (Constant.PROFILE_FPS) {
      sInstance.mWindowManager.removeView(sInstance.mTextView);
    }
    sInstance.mBubbleDraggable.destroy();
    sInstance.mBubbleFlowDraggable.destroy();
    sInstance.mCanvasView.destroy();
    sInstance.mChoreographer.removeFrameCallback(sInstance);
    sInstance.endAppPolling();
    sInstance = null;
  }
Пример #5
0
 @SuppressWarnings("deprecation")
 public void clearCookies(Context context) {
   CookieSyncManager.createInstance(context);
   CookieManager cookieManager = CookieManager.getInstance();
   cookieManager.removeAllCookie();
   CookieSyncManager.getInstance().sync();
 }
Пример #6
0
  public String getCookie(String url) {
    final CookieManager cookieManager = CookieManager.getInstance();
    String cookie = cookieManager.getCookie(url);

    if (cookie == null || cookie.length() == 0) {
      final HttpHead head = new HttpHead(url);
      HttpEntity entity = null;
      try {
        final HttpResponse response = HttpManager.execute(head);
        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
          entity = response.getEntity();

          final Header[] cookies = response.getHeaders("set-cookie");
          for (Header cooky : cookies) {
            cookieManager.setCookie(url, cooky.getValue());
          }

          CookieSyncManager.getInstance().sync();
          cookie = cookieManager.getCookie(url);
        }
      } catch (IOException e) {
        Log.e(LOG_TAG, "Could not retrieve cookie", e);
      } finally {
        if (entity != null) {
          try {
            entity.consumeContent();
          } catch (IOException e) {
            Log.e(LOG_TAG, "Could not retrieve cookie", e);
          }
        }
      }
    }

    return cookie;
  }
Пример #7
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mSpinner = new ProgressDialog(getContext());

    mSpinner.requestWindowFeature(Window.FEATURE_NO_TITLE);
    mSpinner.setMessage("Loading...");

    mContent = new LinearLayout(getContext());

    mContent.setOrientation(LinearLayout.VERTICAL);

    setUpTitle();
    setUpWebView();

    Display display = getWindow().getWindowManager().getDefaultDisplay();
    final float scale = getContext().getResources().getDisplayMetrics().density;
    float[] dimensions =
        (display.getWidth() < display.getHeight()) ? DIMENSIONS_PORTRAIT : DIMENSIONS_LANDSCAPE;

    addContentView(
        mContent,
        new FrameLayout.LayoutParams(
            (int) (dimensions[0] * scale + 0.5f), (int) (dimensions[1] * scale + 0.5f)));

    CookieSyncManager.createInstance(getContext());

    CookieManager cookieManager = CookieManager.getInstance();

    cookieManager.removeAllCookie();
  }
 /** 同步一下cookie */
 public static void synCookies(Context context, String url, String cookies) {
   CookieSyncManager.createInstance(context);
   CookieManager cookieManager = CookieManager.getInstance();
   cookieManager.setAcceptCookie(true);
   cookieManager.removeSessionCookie(); // 移除
   cookieManager.setCookie(url, cookies); // cookies是在HttpClient中获得的cookie
   CookieSyncManager.getInstance().sync();
 }
Пример #9
0
  public void removeCookies() {
    try {
      CookieSyncManager.createInstance(this);
      CookieManager cookieManager = CookieManager.getInstance();
      cookieManager.removeAllCookie();
    } catch (Throwable t) {

    }
  }
 public void testb3167208() throws Exception {
   String uri = "http://host.android.com/path/";
   // note the space after the domain=
   String problemCookie = "foo=bar; domain= .android.com; path=/";
   mCookieManager.setCookie(uri, problemCookie);
   String cookie = mCookieManager.getCookie(uri);
   assertNotNull(cookie);
   assertTrue(cookie.contains("foo=bar"));
 }
Пример #11
0
 public static void setCookie(Context context) {
   if (!StringUtil.isEmpty(CustomerUtil.getAuthenTick())) {
     CookieSyncManager.createInstance(context);
     CookieManager cookieManager = CookieManager.getInstance();
     cookieManager.setAcceptCookie(true);
     cookieManager.setCookie("http://www.kjt.com/", CustomerUtil.getAuthenTick() + ";path=/");
     CookieSyncManager.getInstance().sync();
   }
 }
Пример #12
0
 /** 同步一下cookie */
 public static void synCookies(Context context, String url) {
   CookieSyncManager.createInstance(context);
   CookieManager cookieManager = CookieManager.getInstance();
   cookieManager.setAcceptCookie(true);
   cookieManager.removeSessionCookie(); // 移除
   String token = SharedPrefsUtil.getValue(Constants.TOKEN, null);
   cookieManager.setCookie(url, "token=" + token + ";path=/"); // cookies是在HttpClient中获得的cookie
   CookieSyncManager.getInstance().sync();
 }
  @TestTargetNew(
      level = TestLevel.COMPLETE,
      method = "getInstance",
      args = {})
  public void testGetInstance() {
    CookieManager c1 = CookieManager.getInstance();
    CookieManager c2 = CookieManager.getInstance();

    assertSame(c1, c2);
  }
Пример #14
0
 public void clearSelf() {
   web.stopLoading();
   web.clearHistory();
   web.clearMatches();
   web.clearFormData();
   web.destroyDrawingCache();
   web = null;
   CookieManager cm = CookieManager.getInstance();
   cm.removeAllCookie();
 }
Пример #15
0
 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();
 }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    if (id == R.id.trigger_sync) {
      refreshItemsFromTable();
    } else if (id == R.id.portal) {
      Uri uriUrl = Uri.parse("http://www.appiplus.com");
      Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
      startActivity(launchBrowser);
    } else if (id == R.id.sync_appointments) {

      SharedPreferences prefs = getSharedPreferences(SHAREDPREFFILE, Context.MODE_PRIVATE);
      Boolean sync = prefs.getBoolean(SYNCACTIVATED, true);

      if (sync) {
        sync = false;
      } else {
        sync = true;
      }

      Editor editor = prefs.edit();
      editor.putBoolean(SYNCACTIVATED, sync);
      editor.commit();

      return true;
    } else if (id == R.id.choose_calendar) {
      Intent calendarIntent = new Intent(this, ChooseCalendar.class);
      startActivity(calendarIntent);
    } else if (id == R.id.signout) {
      SharedPreferences preferences = getSharedPreferences(SHAREDPREFFILE, Context.MODE_PRIVATE);
      preferences.edit().remove(USERIDPREF).commit();
      preferences.edit().remove(TOKENPREF).commit();

      mClient.logout();
      trimCache(this);

      CookieSyncManager.createInstance(this);
      CookieManager cookieManager = CookieManager.getInstance();
      cookieManager.removeAllCookie();

      authenticate(false);
    }
    //noinspection SimplifiableIfStatement
    /*if (id == R.id.action_settings) {
        return true;
    }*/

    return super.onOptionsItemSelected(item);
  }
  private void configureCookies(String url) {

    final CookieManager cookieManager = CookieManager.getInstance();

    String cookieHeader = cookieManager.getCookie(url);

    if (cookieHeader != null) {

      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        cookieManager.removeAllCookies(null);
      } else {
        cookieManager.removeAllCookie();
      }

      // We want to always enter in a not-logged-in state.  If the webview has a cookie indicating
      // it has logged in then it will bypass login and go to the .com site.  Remove that cookie.
      // Also, with CookieManager there is no direct way to remove a cookie.  We just iterate the
      // full set and only add back the cookies we want.
      String[] cookies = cookieHeader.split(";");
      for (String cookie : cookies) {
        if (!cookie.trim().startsWith(ACCESS_TOKEN_COOKIE + '=')) {
          cookieManager.setCookie(url, cookie);
        }
      }
    }

    // Add the small view cookie.
    // TODO: In a future release, determine the device size (phone v. tablet) and set the correct
    // cookie value for size
    cookieManager.setCookie(url, "idl_icc=s");

    Log.e(TAG, "configureCookies cookie manager : " + cookieManager.getCookie(url));
  }
  @Override
  public void onPageFinished(WebView view, String url) {
    super.onPageFinished(view, url);
    String authCookie = "";
    String cookies;
    switch (service) {
      case 'p':
        if (url.contains("pna.utexas.edu")) {
          cookies = CookieManager.getInstance().getCookie("https://pna.utexas.edu");
          if (cookies != null && cookies.contains("AUTHCOOKIE=")) {
            for (String s : cookies.split("; ")) {
              if (s.startsWith("AUTHCOOKIE=")) {
                authCookie = s.substring(11);
                break;
              }
            }
          }
          if (!authCookie.equals("")) {
            AuthCookie pnaAuthCookie =
                UTilitiesApplication.getInstance().getAuthCookie(PNA_AUTH_COOKIE_KEY);
            pnaAuthCookie.setAuthCookieVal(authCookie);
            continueToActivity("UT PNA");
            return;
          }
        }
        break;

      case 'u':
        if (url.contains("utexas.edu")) {
          cookies = CookieManager.getInstance().getCookie("https://login.utexas.edu");
          if (cookies != null) {
            for (String s : cookies.split("; ")) {
              if (s.startsWith("utlogin-prod=")) {
                authCookie = s.substring(13);
                break;
              }
            }
          }
          if (!authCookie.equals("") && url.equals("https://www.utexas.edu/")) {
            AuthCookie utdAuthCookie =
                UTilitiesApplication.getInstance().getAuthCookie(UTD_AUTH_COOKIE_KEY);
            utdAuthCookie.setAuthCookieVal(authCookie);
            continueToActivity("UTLogin");
            return;
          }
        }
        break;
    }
  }
Пример #19
0
 /**
  * Gets all cookies for a given domain name
  *
  * @param domain Domain name to fetch cookies for
  * @return Set of cookie objects for given domain
  */
 public List<Cookie> getCookies(String domain) {
   cookieManager.removeExpiredCookie();
   String cookies = cookieManager.getCookie(domain);
   List<Cookie> result = new LinkedList<Cookie>();
   if (cookies == null) {
     return result;
   }
   for (String cookie : cookies.split(COOKIE_SEPARATOR)) {
     String[] cookieValues = cookie.split("=");
     if (cookieValues.length >= 2) {
       result.add(new Cookie(cookieValues[0].trim(), cookieValues[1], domain, null, null));
     }
   }
   return result;
 }
Пример #20
0
  @SuppressWarnings("deprecation")
  public void init(Object jsWebViewInterface, Object jsHandler) {
    if (JSBridgeInteface.class.isInstance(jsWebViewInterface)) {
      this.jsWebViewInterface = (JSBridgeInteface) jsWebViewInterface;
    }
    if (JSBridgeHandler.class.isInstance(jsHandler)) {
      this.jsBridgeHandler = (JSBridgeHandler) jsHandler;
    }
    CookieManager.getInstance().setAcceptCookie(true);
    if (webView != null) {
      webView.getSettings().setJavaScriptEnabled(true);
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
      }

      webView.getSettings().setDomStorageEnabled(true);
      webView.getSettings().setDatabaseEnabled(true);
      if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        webView
            .getSettings()
            .setDatabasePath("/data/data/" + webView.getContext().getPackageName() + "/databases/");
      }

      registerJavaScriptAPI(new AndroidAPI(context, webView));
      webView.setWebViewClient(new JSBridgeWebViewClient());
      webView.loadUrl("javascript: " + getAssetFileContents(JS_BRIDGE_FILE_NAME));
    }
  }
Пример #21
0
    public WebViewHolder(View itemView, Context context) {
      super(itemView);
      mWebView = (WebView) itemView.findViewById(R.id.web_view);
      mWebView.getSettings().setJavaScriptEnabled(true);
      mWebView.getSettings().setBuiltInZoomControls(false);
      mWebView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
      mWebView.getSettings().setAppCacheEnabled(true);
      mWebView.getSettings().setDomStorageEnabled(true);
      mWebView.getSettings().setAppCacheMaxSize(1024 * 1024 * 4);
      mWebView.getSettings().setUseWideViewPort(true);
      mWebView.getSettings().setLoadWithOverviewMode(true);
      String appCachePath = context.getApplicationContext().getCacheDir().getAbsolutePath();
      mWebView.getSettings().setAppCachePath(appCachePath);
      mWebView.getSettings().setAllowFileAccess(true);
      mWebView.loadUrl("http://designtest.zuimeia.com/article/mobile/webview/40/");
      CookieManager.getInstance().setAcceptCookie(true);
      Log.e(TAG, "WebViewHolder: ");

      mWebView.setWebViewClient(
          new WebViewClient() {

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

      setIsRecyclable(true);
    }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case R.id.delete_cookies:
       {
         CookieSyncManager.createInstance(getActivity());
         CookieManager cookieManager = CookieManager.getInstance();
         cookieManager.removeAllCookie();
         return true;
       }
     default:
       {
         return super.onOptionsItemSelected(item);
       }
   }
 }
Пример #23
0
  public void updateIncognitoMode(boolean incognito) {
    CookieSyncManager.createInstance(mContext);
    CookieManager.getInstance().setAcceptCookie(true);

    if (mBubbleFlowDraggable != null) {
      mBubbleFlowDraggable.updateIncognitoMode(incognito);
    }
  }
Пример #24
0
 public void addCookie(Cookie paramCookie) {
   String str1 = paramCookie.getName();
   this.mCookies.put(str1, paramCookie);
   SharedPreferences.Editor localEditor = this.mCookiePrefs.edit();
   localEditor.putString("names", TextUtils.join(",", this.mCookies.keySet()));
   localEditor.putString("cookie_" + str1, encodeCookie(new SerializableCookie(paramCookie)));
   localEditor.commit();
   CookieManager localCookieManager = CookieManager.getInstance();
   String str2 =
       paramCookie.getName()
           + "="
           + paramCookie.getValue()
           + "; domain="
           + paramCookie.getDomain();
   localCookieManager.setCookie(paramCookie.getDomain(), str2);
   CookieSyncManager.getInstance().sync();
 }
Пример #25
0
  private void clearCachedAuthenticationData() {
    if (oauthView != null) {
      oauthView.clearCache(true);
      oauthView.clearFormData();
      oauthView.clearHistory();
    }
    // wipe out cookies.
    CookieSyncManager.createInstance(this);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();

    deleteDatabase("webview.db");
    deleteDatabase("webviewCache.db");
    File cacheDirectory = getCacheDir();
    SdkUtils.deleteFolderRecursive(cacheDirectory);
    cacheDirectory.mkdir();
  }
Пример #26
0
  private void loginWithTwitterWeb() {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(Constants.TWITTER_CONSUMER_KEY);
    builder.setOAuthConsumerSecret(Constants.TWITTER_CONSUMER_SECRET);
    twitter4j.conf.Configuration configuration = builder.build();

    TwitterFactory factory = new TwitterFactory(configuration);
    twitter = factory.getInstance();

    CookieSyncManager.createInstance(mContext);
    CookieManager cookiemanager = CookieManager.getInstance();
    cookiemanager.removeSessionCookie();
    twitter.setOAuthAccessToken(null);

    mTwitterWebDialog = new WebDialog(mContext, twitter);
    mTwitterWebDialog.show();
  }
  @OnClick(R.id.logout_btn)
  public void logoutBtnClicked() {
    final WebView webView = (WebView) this.findViewById(R.id.webView);
    WebViewController.getInstance()
        .logout(); // don't know why this doesn't work, when logout from appmainpage

    CookieManager.getInstance().removeAllCookie(); // TODO don't know , why this works only here.
  }
Пример #28
0
  @SuppressWarnings("deprecation")
  private void setCookie(Context context) {
    CookieSyncManager.createInstance(context);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();
    cookieManager.setAcceptCookie(true);
    for (int i = 0; i < cookies.size(); i++) {
      Cookie cookie = cookies.get(i);
      String cookieName = cookie.getName();
      String cookieValue = cookie.getValue();
      String domainString = cookie.getDomain();
      //			Log.i("FRAGHOME",cookieName);
      //			Log.i("FRAGHOME",cookieValue);
      //			Log.i("FRAGHOME",domainString);
      if (!cookieName.isEmpty() && !cookieValue.isEmpty() && !domainString.isEmpty()) {
        cookieManager.setCookie(domainString, cookieName + "=" + cookieValue);
      }
    }

    //		cookieManager.setCookie(baseURL, "uid=123");
    CookieSyncManager.getInstance().sync();
    if (cookieManager.getCookie(devbaseURL) != null) {
      System.out.println(cookieManager.getCookie(devbaseURL));
    }
    //		webview.loadUrl(baseURL+"?app-get_top_cate");
    //		System.out.println(cookieManager.getCookie(baseURL));
  }
Пример #29
0
 public void onCreate() {
   if (LOGV_ENABLED) Log.v(LOGTAG, "Browser.onCreate: this=" + this);
   // Fix heap utilization for better heap size characteristics.
   VMRuntime.getRuntime().setTargetHeapUtilization(TARGET_HEAP_UTILIZATION);
   // create CookieSyncManager with current Context
   CookieSyncManager.createInstance(this);
   // remove all expired cookies
   CookieManager.getInstance().removeExpiredCookie();
 }
Пример #30
0
  @Override
  public void unauth() {

    token = null;

    CookieSyncManager.createInstance(act);
    CookieManager.getInstance().removeAllCookie();
    storeToken(null, null);
  }