com.loopj.android.http.PersistentCookieStore Java Examples

The following examples show how to use com.loopj.android.http.PersistentCookieStore. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MyAsyncHttpClient.java    From school_shop with MIT License 6 votes vote down vote up
public static AsyncHttpClient createClient(Context context) {
    AsyncHttpClient client = new AsyncHttpClient();
    PersistentCookieStore cookieStore = new PersistentCookieStore(context);
    client.setCookieStore(cookieStore);

    return client;
}
 
Example #2
Source File: MainActivity.java    From Android-ImageManager with MIT License 6 votes vote down vote up
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    gridView = (GridView)findViewById(R.id.gridView);

    final PersistentCookieStore myCookieStore = new PersistentCookieStore(this);
    httpClient.setCookieStore(myCookieStore);

    if (!DiskLruImageCache.isInitialized()) {
        new AsyncTask<Void, Void, Void>() {
            @Override
            protected Void doInBackground(final Void... params) {
                DiskLruImageCache.getInstance(MainActivity.this);
                return null;
            }

            @Override
            protected void onPostExecute(final Void result) {
                initGrid();
            }
        }.execute();
    }
}
 
Example #3
Source File: HttpUtilsAsync.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * Perform a HTTP POST request with cookies which are defined in hashmap
 *
 * @param context
 * @param url
 * @param hashMap
 * @param responseHandler
 */
public static void postUseCookie(Context context, String url, HashMap hashMap, AsyncHttpResponseHandler responseHandler) {
    PersistentCookieStore myCookieStore = new PersistentCookieStore(context);
    if (BasicUtils.judgeNotNull(hashMap)) {
        Iterator iterator = hashMap.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry entry = (Map.Entry) iterator.next();
            Object key = entry.getKey();
            Object value = entry.getValue();
            Cookie cookie = new BasicClientCookie(key.toString(), value.toString());
            myCookieStore.addCookie(cookie);
        }
    }
    AsyncHttpClient client = new AsyncHttpClient();
    client.setCookieStore(myCookieStore);
    client.post(getAbsoluteUrl(url), responseHandler);
}
 
Example #4
Source File: HttpUtilsAsync.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * Perform a HTTP POST request with cookie which generate by own context
 *
 * @param context
 * @param url
 * @param responseHandler
 */
public static void postWithCookie(Context context, String url, AsyncHttpResponseHandler responseHandler) {
    AsyncHttpClient client = new AsyncHttpClient();
    PersistentCookieStore myCookieStore = new PersistentCookieStore(context);
    //  myCookieStore.clear();
    client.setCookieStore(myCookieStore);
    client.post(getAbsoluteUrl(url), responseHandler);
}
 
Example #5
Source File: HttpUtilsAsync.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * Perform a HTTP GET request with cookies which are defined in hashmap
 *
 * @param context
 * @param url
 * @param hashMap
 * @param responseHandler
 */
public static void getUseCookie(Context context, String url, HashMap hashMap, AsyncHttpResponseHandler responseHandler) {
    PersistentCookieStore myCookieStore = new PersistentCookieStore(context);
    if (BasicUtils.judgeNotNull(hashMap)) {
        Iterator iterator = hashMap.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry entry = (Map.Entry) iterator.next();
            Object key = entry.getKey();
            Object value = entry.getValue();
            Cookie cookie = new BasicClientCookie(key.toString(), value.toString());
            myCookieStore.addCookie(cookie);
        }
    }
    AsyncHttpClient client = new AsyncHttpClient();
    client.setCookieStore(myCookieStore);
    client.get(getAbsoluteUrl(url), responseHandler);
}
 
Example #6
Source File: HttpUtilsAsync.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * Perform a HTTP GET request with cookie which generate by own context
 *
 * @param context
 * @param url
 * @param responseHandler
 */
public static void getWithCookie(Context context, String url, AsyncHttpResponseHandler responseHandler) {
    AsyncHttpClient client = new AsyncHttpClient();
    PersistentCookieStore myCookieStore = new PersistentCookieStore(context);
    //  myCookieStore.clear();
    client.setCookieStore(myCookieStore);
    client.get(getAbsoluteUrl(url), responseHandler);

}
 
Example #7
Source File: WriteAnswerActivity.java    From WeCenterMobile-Android with GNU General Public License v2.0 6 votes vote down vote up
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
	// TODO Auto-generated method stub
	super.onCreate(savedInstanceState);
	setContentView(R.layout.write_answer);
	actionBar = getActionBar();
	actionBar.setIcon(null);
	actionBar.setTitle("�ش�");
	actionBar.setDisplayUseLogoEnabled(false);
	actionBar.setDisplayHomeAsUpEnabled(true);
	actionBar.show();
	Intent intent = getIntent();
	question_id = intent.getStringExtra("questionid");
	attach_access_key = md5(getAttachKey());
	dp = getResources().getDimension(R.dimen.dp);
	editText = (EditText) findViewById(R.id.answerdetil);
	selectimg_horizontalScrollView = (HorizontalScrollView) findViewById(R.id.selectimg_horizontalScrollView);
	gridview = (GridView) findViewById(R.id.noScrollgridview);
	gridview.setSelector(new ColorDrawable(Color.TRANSPARENT));
	client = new AsyncHttpClient();
	myCookieStore = new PersistentCookieStore(this);
	client.setCookieStore(myCookieStore);
	progressDialog = new MyProgressDialog(this, "���ڼ�����", "���Ժ�...", false);
	gridviewInit();
}
 
Example #8
Source File: AsyncFileUpLoad.java    From WeCenterMobile-Android with GNU General Public License v2.0 6 votes vote down vote up
public AsyncFileUpLoad(Context context, String url, String filePath,
		CallBack callBack) {
	Log.i("url", url);
	Log.i("filePath", filePath);
	this.context = context;
	this.url = url;
	file = new File(filePath);
	NetworkState networkState = new NetworkState();
	client = new AsyncHttpClient();
	PersistentCookieStore mCookieStore = new PersistentCookieStore(context);
	client.setCookieStore(mCookieStore);
	if (networkState.isNetworkConnected(context)) {
		//Login();
		upLoad(callBack);
	} else {
		showTips(R.drawable.tips_error, R.string.net_break);
	}

}
 
Example #9
Source File: AskingFragmentActivity.java    From WeCenterMobile-Android with GNU General Public License v2.0 6 votes vote down vote up
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle arg0) {
	// TODO Auto-generated method stub
	super.onCreate(arg0);
	setContentView(R.layout.question_pager);
	actionBar = getActionBar();
	actionBar.setIcon(null);
	actionBar.setTitle("提问");
	actionBar.setDisplayUseLogoEnabled(false);
	actionBar.setDisplayHomeAsUpEnabled(true);
	actionBar.show();
	text1 = new AskingFragment();
	text2 = new DetailFragment();
	text3 = new TagFragment();
	cursor = (ImageView) findViewById(R.id.cursor);
	attach_access_key = md5(getAttachKey());
	client = new AsyncHttpClient();
	myCookieStore = new PersistentCookieStore(this);
	client.setCookieStore(myCookieStore);
	progressDialog = new MyProgressDialog(this, "正在上传", "稍等...", false);
	InitTextView();
	InitImageView();
	InitViewPager();

}
 
Example #10
Source File: MainActivity.java    From WeCenterMobile-Android with GNU General Public License v2.0 6 votes vote down vote up
@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.feedback) {
		FeedbackAgent agent = new FeedbackAgent(MainActivity.this);
		agent.startFeedbackActivity();
	}
	if (id == R.id.logout) {
		sharedPreferences.clear();
		PersistentCookieStore cookieStore = new PersistentCookieStore(
				MainActivity.this);
		cookieStore.clear();
		Intent intent = new Intent(this, MainActivity.class);
		intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		startActivity(intent);
		return true;
	}
	return super.onOptionsItemSelected(item);
}
 
Example #11
Source File: WelcomeActivity.java    From WeCenterMobile-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	// TODO Auto-generated method stub
	super.onCreate(savedInstanceState);

	PersistentCookieStore cookieStore = new PersistentCookieStore(
			WelcomeActivity.this);
	FanfanSharedPreferences fanfanSharedPreferences = new FanfanSharedPreferences(
			WelcomeActivity.this);
	boolean LoginStatus = fanfanSharedPreferences.getLogInStatus(false);
	String uid = fanfanSharedPreferences.getUid("");
	String userName = fanfanSharedPreferences.getUserName("");
	String passwd = fanfanSharedPreferences.getPasswd("");
	if (LoginStatus != false && !uid.equals("") && !passwd.equals("")
			&& !userName.equals("") && cookieStore.getCookies().size() != 0) {
		Intent intent = new Intent(WelcomeActivity.this, MainActivity.class);
		startActivity(intent);
		finish();
	}
	requestWindowFeature(Window.FEATURE_NO_TITLE);
	setContentView(R.layout.welcome);
	init();
}
 
Example #12
Source File: FlowAsyncClient.java    From flow-android with MIT License 5 votes vote down vote up
public static void init(Context c) {
    cookieStore = new PersistentCookieStore(c);
    client.setCookieStore(cookieStore);

    preferences = PreferenceManager.getDefaultSharedPreferences(c);
    csrfToken = preferences.getString(CSRF_PREFERENCE_KEY, null);
    useCsrfToken();
}
 
Example #13
Source File: EssayCommentActivity.java    From WeCenterMobile-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	// TODO Auto-generated method stub
	super.onCreate(savedInstanceState);
	setContentView(R.layout.comment_list);

	ActionBar actionBar = getActionBar();
	actionBar.setIcon(null);
	actionBar.setTitle("��������");
	actionBar.setDisplayUseLogoEnabled(false);
	actionBar.setDisplayHomeAsUpEnabled(true);
	actionBar.show();
	Intent intent = getIntent();
	id = intent.getStringExtra("artid");
	client = new AsyncHttpClient();
	myCookieStore = new PersistentCookieStore(this);
	client.setCookieStore(myCookieStore);
	comment = (EditText) findViewById(R.id.comment);
	publish = (ImageButton) findViewById(R.id.publish);
	publish.setOnClickListener(new OnClickListener() {

		@Override
		public void onClick(View arg0) {
			// TODO Auto-generated method stub
			RequestParams params = new RequestParams();
			params.put("article_id", id);
			params.put("message", comment.getText().toString());
			params.put("at_uid", atuid);
			postcom(params);
			comment.setText("");
			refresh();
		}
	});
	comitems = new ArrayList<EssayCommentModel>();
	imageDownLoader = new ImageDownLoader(this);
	comlist = (ListView) findViewById(R.id.comlist);
	isFirstEnter = true;
	comlist.setOnItemClickListener(this);
	comlist.setOnScrollListener(this);

	Getcom(id);

}
 
Example #14
Source File: V2EX.java    From v2ex-daily-android with Apache License 2.0 4 votes vote down vote up
public static void logout(Context context){
    PersistentCookieStore cookieStore = new PersistentCookieStore(context);
    cookieStore.clear();
}
 
Example #15
Source File: UserInfoShowActivity.java    From WeCenterMobile-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onClick(View v) {
	// TODO Auto-generated method stub
	switch (v.getId()) {
	case R.id.ll_logout:
		// �˳���¼
		sharedPreferences = new FanfanSharedPreferences(
				UserInfoShowActivity.this);
		sharedPreferences.clear();
		PersistentCookieStore cookieStore = new PersistentCookieStore(
				UserInfoShowActivity.this);
		cookieStore.clear();
		Intent mainIntent = new Intent(this, MainActivity.class);
		mainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		startActivity(mainIntent);
		break;
	case R.id.lv_topics:
		Intent intent = new Intent(UserInfoShowActivity.this,
				TopicFragmentActivity.class);
		intent.putExtra("uid", uid);
		startActivity(intent);
		break;
	case R.id.lv_focusi_person:
		Intent intent2 = new Intent(UserInfoShowActivity.this,
				AttentionUserActivity.class);
		intent2.putExtra("userorme", GlobalVariables.ATTENEION_ME);
		intent2.putExtra("uid", uid);
		startActivity(intent2);
		break;
	case R.id.lv_ifocus_person:
		Intent intent1 = new Intent(UserInfoShowActivity.this,
				AttentionUserActivity.class);
		intent1.putExtra("uid", uid);
		intent1.putExtra("userorme", GlobalVariables.ATTENTION_USER);
		startActivity(intent1);
		break;
	case R.id.lv_articles:
		Intent intent3 = new Intent(UserInfoShowActivity.this,
				ArticleActivity.class);
		intent3.putExtra("isArticle", GlobalVariables.ARTICLE);
		intent3.putExtra("uid", uid);
		startActivity(intent3);
		break;
	case R.id.lv_asks:
		Intent intent4 = new Intent(UserInfoShowActivity.this,
				ArticleActivity.class);
		intent4.putExtra("isArticle", GlobalVariables.QUESTION);
		intent4.putExtra("uid", uid);
		startActivity(intent4);
		break;
	case R.id.lv_news:
		Toast.makeText(UserInfoShowActivity.this, "lv_news",
				Toast.LENGTH_SHORT).show();
		break;
	case R.id.lv_search_friens:
		Toast.makeText(UserInfoShowActivity.this, "lv_search_friens",
				Toast.LENGTH_SHORT).show();
		break;
	case R.id.lv_replys:
		Intent intent5 = new Intent(UserInfoShowActivity.this,
				MyAnswerActivity.class);
		intent5.putExtra("uid", uid);
		startActivity(intent5);
		break;
	case R.id.bt_focus:
		if (haveFrocus == YES) {
			haveFrocus = NO;
			bt_focus.setBackgroundResource(R.drawable.btn_green_normal);
			bt_focus.setTextColor(android.graphics.Color.WHITE);
			bt_focus.setText("��ע");
		} else {
			haveFrocus = YES;
			bt_focus.setBackgroundResource(R.drawable.btn_silver_normal);
			bt_focus.setTextColor(android.graphics.Color.BLACK);
			bt_focus.setText("ȡ����ע");
		}
		pb_change_follow.setVisibility(View.VISIBLE);
		changeFrocusStatus();
		bt_focus.setClickable(false);
		break;
	default:
		break;
	}
}
 
Example #16
Source File: AsyncHttpHelper.java    From LiveVideo with Apache License 2.0 4 votes vote down vote up
/**
 * 设置持久化保存cookie
 */
public static void saveCookie(Context context) {
	AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
	PersistentCookieStore cookieStore = new PersistentCookieStore(context);
	asyncHttpClient.setCookieStore(cookieStore);
}
 
Example #17
Source File: HttpUtilsAsync.java    From UltimateAndroid with Apache License 2.0 3 votes vote down vote up
/**
 * Perform a HTTP GET request with cookie which generate by own context
 *
 * @param context
 * @param url
 * @param responseHandler
 */
public static void getWithCookie(Context context, String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
    AsyncHttpClient client = new AsyncHttpClient();
    PersistentCookieStore myCookieStore = new PersistentCookieStore(context);
    client.setCookieStore(myCookieStore);
    client.get(getAbsoluteUrl(url), params, responseHandler);
}
 
Example #18
Source File: HttpUtilsAsync.java    From UltimateAndroid with Apache License 2.0 3 votes vote down vote up
/**
 * Perform a HTTP POST request with cookie which generate by own context
 *
 * @param context
 * @param url
 * @param params
 * @param responseHandler
 */
public static void postWithCookie(Context context, String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
    AsyncHttpClient client = new AsyncHttpClient();
    PersistentCookieStore myCookieStore = new PersistentCookieStore(context);
    client.setCookieStore(myCookieStore);
    client.post(getAbsoluteUrl(url), params, responseHandler);
}