Java Code Examples for com.lidroid.xutils.HttpUtils#configDefaultHttpCacheExpiry()

The following examples show how to use com.lidroid.xutils.HttpUtils#configDefaultHttpCacheExpiry() . 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: MeiTuServiceImpl.java    From QiQuYing with Apache License 2.0 5 votes vote down vote up
@Override
public void getMeiTu(final Handler handler, int newOrHotFlag, int offset,
		int count) {
	HttpUtils http = new HttpUtils();
	http.configDefaultHttpCacheExpiry(1000 * 60 * 10); //缓存超期时间10分钟
	http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
	RequestParams params = new RequestParams();
	params.addQueryStringParameter("newOrHotFlag", String.valueOf(newOrHotFlag));
	params.addQueryStringParameter("offset", String.valueOf(offset));
	params.addQueryStringParameter("count", String.valueOf(count));
	http.send(HttpRequest.HttpMethod.GET,
		RcpUri.INTERFACE_URI_LIST, params,
		new RequestCallBack<String>() {
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				String rs = responseInfo.result;
				Map map = FastjsonUtil.json2Map(rs);
				int code = Integer.parseInt(String.valueOf(map.get("code")));
				if (code != 200) {
					//请求失败
					handler.sendEmptyMessage(Constants.FAILURE);
					return;
				}
				PageResult page = FastjsonUtil.deserialize(
						map.get("data").toString(), PageResult.class);
				Message message = new Message();
				Bundle bundle = new Bundle();
				bundle.putSerializable("pageResult", page);
				message.what = Constants.SUCCESS;
				message.setData(bundle);
				handler.sendMessage(message);
			}
			@Override
			public void onFailure(HttpException error, String msg) {
				handler.sendEmptyMessage(Constants.FAILURE);
			}
		});
}
 
Example 2
Source File: JokeServiceImpl.java    From QiQuYing with Apache License 2.0 5 votes vote down vote up
@Override
public void getJokeById(final ApiCallBack apiCallBack, Integer jokeId) {
	HttpUtils http = new HttpUtils();
	http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
	http.configDefaultHttpCacheExpiry(0); 
	RequestParams params = new RequestParams();
	params.addQueryStringParameter("jokeId", String.valueOf(jokeId));
	http.send(HttpRequest.HttpMethod.GET,
		RcpUri.INTERFACE_URI_GET_JOKE, params,
		new RequestCallBack<String>() {
			@SuppressWarnings("rawtypes")
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				String rs = responseInfo.result;
				Map map = FastjsonUtil.json2Map(rs);
				int code = Integer.parseInt(String.valueOf(map.get("code")));
				if(code == Constants.SUCCESS) {
					Log.e(TAG, "getJokeById success");
					Joke joke = FastjsonUtil.deserialize(
							map.get("data").toString(), Joke.class);
					apiCallBack.onSuccess(joke);
				} else {
					Log.e(TAG, "getJokeById fail, fail msg is " + map.get("msg"));
					apiCallBack.onFailure(String.valueOf(code));
				}
			}
			@Override
			public void onFailure(HttpException error, String msg) {
				Log.e(TAG, "getJokeById error", error);
				if(!HttpUtil.isNetworkAvailable(mContext)) {
					ToastUtils.showMessage(mContext, R.string.no_net);
				} else {
					apiCallBack.onError(error, msg);
				}
			}
		});
}
 
Example 3
Source File: JokeServiceImpl.java    From QiQuYing with Apache License 2.0 5 votes vote down vote up
@Override
public void getCommentByJokeId(final Handler handler, int jokeId, int offset,
		int count) {
	HttpUtils http = new HttpUtils();
	http.configDefaultHttpCacheExpiry(60); //缓存超期时间10分钟
	http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
	RequestParams params = new RequestParams();
	params.addQueryStringParameter("qushiId", String.valueOf(jokeId));
	params.addQueryStringParameter("offset", String.valueOf(offset));
	params.addQueryStringParameter("count", String.valueOf(count));
	http.send(HttpRequest.HttpMethod.GET,
		RcpUri.INTERFACE_URI_GET_COMMENTS, params,
		new RequestCallBack<String>() {
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				String rs = responseInfo.result;
				Map map = FastjsonUtil.json2Map(rs);
				int code = Integer.parseInt(String.valueOf(map.get("code")));
				if (code != 200) {
					//请求失败
					handler.sendEmptyMessage(Constants.FAILURE);
					return;
				}
				PageResult page = FastjsonUtil.deserialize(
						map.get("data").toString(), PageResult.class);
				Message message = new Message();
				Bundle bundle = new Bundle();
				bundle.putSerializable("pageResult", page);
				message.what = Constants.SUCCESS;
				message.setData(bundle);
				handler.sendMessage(message);
			}
			@Override
			public void onFailure(HttpException error, String msg) {
				handler.sendEmptyMessage(Constants.FAILURE);
			}
		});
}
 
Example 4
Source File: JokeServiceImpl.java    From QiQuYing with Apache License 2.0 5 votes vote down vote up
@Override
public void refushAll(final Handler handler, int newOrHotFlag, int count) {
	HttpUtils http = new HttpUtils();
	http.configDefaultHttpCacheExpiry(0); //缓存超期时间0分钟
	http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
	RequestParams params = new RequestParams();
	params.addQueryStringParameter("newOrHotFlag", String.valueOf(newOrHotFlag));
	params.addQueryStringParameter("count", String.valueOf(count));
	http.send(HttpRequest.HttpMethod.GET,
		RcpUri.INTERFACE_URI_LIST, params,
		new RequestCallBack<String>() {
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				try {
					String rs = responseInfo.result;
					Map map = FastjsonUtil.json2Map(rs);
					int code = Integer.parseInt(String.valueOf(map.get("code")));
					if (code != 200) {
						//请求失败
						handler.sendEmptyMessage(Constants.FAILURE);
						return;
					}
					PageResult page = FastjsonUtil.deserialize(
							map.get("data").toString(), PageResult.class);
					Message message = new Message();
					Bundle bundle = new Bundle();
					bundle.putSerializable("pageResult", page);
					message.what = Constants.SUCCESS_1;
					message.setData(bundle);
					handler.sendMessage(message);
				} catch (Exception e) {
					handler.sendEmptyMessage(Constants.FAILURE);
				}
			}
			@Override
			public void onFailure(HttpException error, String msg) {
				handler.sendEmptyMessage(Constants.FAILURE);
			}
		});
}
 
Example 5
Source File: MeiTuServiceImpl.java    From QiQuYing with Apache License 2.0 5 votes vote down vote up
@Override
public void refresh(final Handler handler, int newOrHotFlag, int count) {
	HttpUtils http = new HttpUtils();
	http.configDefaultHttpCacheExpiry(0); //缓存超期时间10分钟
	http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
	RequestParams params = new RequestParams();
	params.addQueryStringParameter("newOrHotFlag", String.valueOf(newOrHotFlag));
	params.addQueryStringParameter("count", String.valueOf(count));
	http.send(HttpRequest.HttpMethod.GET,
		RcpUri.INTERFACE_URI_LIST, params,
		new RequestCallBack<String>() {
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				String rs = responseInfo.result;
				Map map = FastjsonUtil.json2Map(rs);
				int code = Integer.parseInt(String.valueOf(map.get("code")));
				if (code != 200) {
					//请求失败
					handler.sendEmptyMessage(Constants.FAILURE);
					return;
				}
				PageResult page = FastjsonUtil.deserialize(
						map.get("data").toString(), PageResult.class);
				Message message = new Message();
				Bundle bundle = new Bundle();
				bundle.putSerializable("pageResult", page);
				message.what = Constants.SUCCESS_1;
				message.setData(bundle);
				handler.sendMessage(message);
			}
			@Override
			public void onFailure(HttpException error, String msg) {
				handler.sendEmptyMessage(Constants.FAILURE);
			}
		});
}
 
Example 6
Source File: QuTuServiceImpl.java    From QiQuYing with Apache License 2.0 5 votes vote down vote up
@Override
	public void refush(final Handler handler, int newOrHotFlag, int count) {
		HttpUtils http = new HttpUtils();
		http.configDefaultHttpCacheExpiry(0); //缓存超期时间0分钟
		http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
		RequestParams params = new RequestParams();
		params.addQueryStringParameter("newOrHotFlag", String.valueOf(newOrHotFlag));
//		params.addQueryStringParameter("offset", String.valueOf(1));
		params.addQueryStringParameter("count", String.valueOf(count));
		http.send(HttpRequest.HttpMethod.GET,
			RcpUri.INTERFACE_URI_LIST, params,
			new RequestCallBack<String>() {
				@Override
				public void onSuccess(ResponseInfo<String> responseInfo) {
					String rs = responseInfo.result;
					Map map = FastjsonUtil.json2Map(rs);
					int code = Integer.parseInt(String.valueOf(map.get("code")));
					if (code != 200) {
						//请求失败
						handler.sendEmptyMessage(Constants.FAILURE);
						return;
					}
					PageResult page = FastjsonUtil.deserialize(
							map.get("data").toString(), PageResult.class);
					Message message = new Message();
					Bundle bundle = new Bundle();
					bundle.putSerializable("pageResult", page);
					message.what = Constants.SUCCESS_1;
					message.setData(bundle);
					handler.sendMessage(message);
				}
				@Override
				public void onFailure(HttpException error, String msg) {
					handler.sendEmptyMessage(Constants.FAILURE);
				}
			});
	}
 
Example 7
Source File: QuTuServiceImpl.java    From QiQuYing with Apache License 2.0 5 votes vote down vote up
@Override
public void getQuTu(final Handler handler, int newOrHotFlag, int offset,
		int count) {
	HttpUtils http = new HttpUtils();
	http.configDefaultHttpCacheExpiry(1000 * 60 * 10); //缓存超期时间10分钟
	http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
	RequestParams params = new RequestParams();
	params.addQueryStringParameter("newOrHotFlag", String.valueOf(newOrHotFlag));
	params.addQueryStringParameter("offset", String.valueOf(offset));
	params.addQueryStringParameter("count", String.valueOf(count));
	http.send(HttpRequest.HttpMethod.GET,
		RcpUri.INTERFACE_URI_LIST, params,
		new RequestCallBack<String>() {
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				String rs = responseInfo.result;
				Map map = FastjsonUtil.json2Map(rs);
				int code = Integer.parseInt(String.valueOf(map.get("code")));
				if (code != 200) {
					//请求失败
					handler.sendEmptyMessage(Constants.FAILURE);
					return;
				}
				PageResult page = FastjsonUtil.deserialize(
						map.get("data").toString(), PageResult.class);
				Message message = new Message();
				Bundle bundle = new Bundle();
				bundle.putSerializable("pageResult", page);
				message.what = Constants.SUCCESS;
				message.setData(bundle);
				handler.sendMessage(message);
			}
			@Override
			public void onFailure(HttpException error, String msg) {
				handler.sendEmptyMessage(Constants.FAILURE);
			}
		});
}
 
Example 8
Source File: UserServiceImpl.java    From QiQuYing with Apache License 2.0 5 votes vote down vote up
@Override
public void reSetPassword(String phone, String password,
		final ApiCallBack apiCallBack) {
	HttpUtils http = new HttpUtils();
	http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
	http.configDefaultHttpCacheExpiry(0); 
	RequestParams params = new RequestParams();
	params.addQueryStringParameter("phone", phone);
	params.addQueryStringParameter("password", password);
	http.send(HttpRequest.HttpMethod.POST,
		RcpUri.INTERFACE_URI_RESET_PWD, params,
		new RequestCallBack<String>() {
			@SuppressWarnings("rawtypes")
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				String rs = responseInfo.result;
				Map map = FastjsonUtil.json2Map(rs);
				int code = Integer.parseInt(String.valueOf(map.get("code")));
				if(code == Constants.SUCCESS) {
					Log.e(TAG, "reSetPassword success");
					User user = FastjsonUtil.deserialize(
							map.get("data").toString(), User.class);
					apiCallBack.onSuccess(user);
				} else {
					Log.e(TAG, "reSetPassword fail, fail msg is " + map.get("msg"));
					apiCallBack.onFailure(String.valueOf(code));
				}
			}
			@Override
			public void onFailure(HttpException error, String msg) {
				Log.e(TAG, "reSetPassword error", error);
				if(!HttpUtil.isNetworkAvailable(mContext)) {
					ToastUtils.showMessage(mContext, R.string.no_net);
				} else {
					apiCallBack.onError(error, msg);
				}
			}
		});
}
 
Example 9
Source File: UserServiceImpl.java    From QiQuYing with Apache License 2.0 5 votes vote down vote up
@Override
public void checkUserExeist(String phone, final ApiCallBack apiCallBack) {
	HttpUtils http = new HttpUtils();
	http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
	http.configDefaultHttpCacheExpiry(0); 
	RequestParams params = new RequestParams();
	params.addQueryStringParameter("phone", phone);
	http.send(HttpRequest.HttpMethod.POST,
		RcpUri.INTERFACE_URI_CHECK_EXEIST, params,
		new RequestCallBack<String>() {
			@SuppressWarnings("rawtypes")
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				String rs = responseInfo.result;
				Map map = FastjsonUtil.json2Map(rs);
				int code = Integer.parseInt(String.valueOf(map.get("code")));
				if(code == Constants.SUCCESS) {
					Log.e(TAG, "checkUserExeist success");
					apiCallBack.onSuccess(code);
				} else {
					Log.e(TAG, "checkUserExeist fail, fail msg is " + map.get("msg"));
					apiCallBack.onFailure(String.valueOf(code));
				}
			}
			@Override
			public void onFailure(HttpException error, String msg) {
				Log.e(TAG, "checkUserExeist error", error);
				if(!HttpUtil.isNetworkAvailable(mContext)) {
					ToastUtils.showMessage(mContext, R.string.no_net);
				} else {
					apiCallBack.onError(error, msg);
				}
			}
		});
}
 
Example 10
Source File: UserServiceImpl.java    From QiQuYing with Apache License 2.0 4 votes vote down vote up
@Override
public void addTencentUser(final Handler handler, String openId, String portraitUrl, String nickName,
		int sex) {
	HttpUtils http = new HttpUtils();
	http.configDefaultHttpCacheExpiry(1000 * 60 * 10); //缓存超期时间10分钟
	http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
	RequestParams params = new RequestParams();
	params.addQueryStringParameter("openId", openId);
	params.addQueryStringParameter("portraitUrl", portraitUrl);
	try {
		params.addQueryStringParameter("nickName", URLEncoder.encode(nickName, "UTF-8"));
	} catch (UnsupportedEncodingException e) {
		e.printStackTrace();
	}
	params.addQueryStringParameter("sex", String.valueOf(sex));
	http.send(HttpRequest.HttpMethod.POST,
		RcpUri.INTERFACE_URI_ADD_TENCENT_USER, params,
		new RequestCallBack<String>() {
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				String rs = responseInfo.result;
				Map map = FastjsonUtil.json2Map(rs);
				int code = Integer.parseInt(String.valueOf(map.get("code")));
				if (code != 200) {
					//请求失败
					handler.sendEmptyMessage(Constants.FAILURE);
					Log.e(TAG, "save user failure");
					return;
				}
				Log.e(TAG, "save user success");
				User user = FastjsonUtil.deserialize(
						map.get("data").toString(), User.class);
				Message message = new Message();
				Bundle bundle = new Bundle();
				bundle.putSerializable("user", user);
				message.what = Constants.SUCCESS;
				message.setData(bundle);
				handler.sendMessage(message);
			}
			@Override
			public void onFailure(HttpException error, String msg) {
				Log.e(TAG, "save user failure", error);
				handler.sendEmptyMessage(Constants.FAILURE);
			}
		});
}
 
Example 11
Source File: JokeServiceImpl.java    From QiQuYing with Apache License 2.0 4 votes vote down vote up
@Override
public void getAll(final Handler handler, int newOrHotFlag, int offset, int count) {
	HttpUtils http = new HttpUtils();
	http.configDefaultHttpCacheExpiry(1000 * 60 * 10); //缓存超期时间10分钟
	http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
	RequestParams params = new RequestParams();
	params.addQueryStringParameter("newOrHotFlag", String.valueOf(newOrHotFlag));
	params.addQueryStringParameter("offset", String.valueOf(offset));
	params.addQueryStringParameter("count", String.valueOf(count));
	http.send(HttpRequest.HttpMethod.GET,
		RcpUri.INTERFACE_URI_LIST, params,
		new RequestCallBack<String>() {
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				try {
					String rs = responseInfo.result;
					Map map = FastjsonUtil.json2Map(rs);
					int code = Integer.parseInt(String.valueOf(map.get("code")));
					if (code != 200) {
						//请求失败
						handler.sendEmptyMessage(Constants.FAILURE);
						return;
					}
					PageResult page = FastjsonUtil.deserialize(
							map.get("data").toString(), PageResult.class);
					Message message = new Message();
					Bundle bundle = new Bundle();
					bundle.putSerializable("pageResult", page);
					message.what = Constants.SUCCESS;
					message.setData(bundle);
					handler.sendMessage(message);
				} catch (Exception e) {
					handler.sendEmptyMessage(Constants.FAILURE);
				}
			}
			@Override
			public void onFailure(HttpException error, String msg) {
				handler.sendEmptyMessage(Constants.FAILURE);
			}
		});
}
 
Example 12
Source File: UserServiceImpl.java    From QiQuYing with Apache License 2.0 4 votes vote down vote up
@Override
public void login(final Handler handler, String email, String password) {
	HttpUtils http = new HttpUtils();
	http.configDefaultHttpCacheExpiry(1000 * 60 * 10); //缓存超期时间10分钟
	http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
	RequestParams params = new RequestParams();
	params.addQueryStringParameter("userName", email);
	params.addQueryStringParameter("password", password);
	http.send(HttpRequest.HttpMethod.POST,
		RcpUri.INTERFACE_URI_LOGIN, params,
		new RequestCallBack<String>() {
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				String rs = responseInfo.result;
				Map map = FastjsonUtil.json2Map(rs);
				int code = Integer.parseInt(String.valueOf(map.get("code")));
				if (code != 200) {
					//请求失败
					handler.sendEmptyMessage(Constants.FAILURE);
					Log.e(TAG, "login failure");
					if(code == 503) {  //用户名不存在
						ToastUtils.showMessage(mContext, R.string.no_account);
						return;
					}
					if(code == 504) {  //登录密码错误
						ToastUtils.showMessage(mContext, R.string.password_error);
						return;
					}
					ToastUtils.showMessage(mContext, R.string.login_fail);
				}
				Log.e(TAG, "login success");
				User user = FastjsonUtil.deserialize(
						map.get("data").toString(), User.class);
				Message message = new Message();
				Bundle bundle = new Bundle();
				bundle.putSerializable("user", user);
				message.what = Constants.SUCCESS;
				message.setData(bundle);
				handler.sendMessage(message);
			}
			@Override
			public void onFailure(HttpException error, String msg) {
				Log.e(TAG, "login failure", error);
				handler.sendEmptyMessage(Constants.FAILURE);
				if(!HttpUtil.isNetworkAvailable(mContext)) {
					ToastUtils.showMessage(mContext, R.string.no_net);
				} else {
					ToastUtils.showMessage(mContext, R.string.login_fail);
				}
			}
		});
}
 
Example 13
Source File: JokeServiceImpl.java    From QiQuYing with Apache License 2.0 4 votes vote down vote up
@Override
public void getList(final Handler handler, int type, int newOrHotFlag, int offset,
		int count) {
	HttpUtils http = new HttpUtils();
	http.configDefaultHttpCacheExpiry(1000 * 60 * 10); //缓存超期时间10分钟
	http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
	RequestParams params = new RequestParams();
	params.addQueryStringParameter("type", String.valueOf(type));
	params.addQueryStringParameter("newOrHotFlag", String.valueOf(newOrHotFlag));
	params.addQueryStringParameter("offset", String.valueOf(offset));
	params.addQueryStringParameter("count", String.valueOf(count));
	http.send(HttpRequest.HttpMethod.GET,
		RcpUri.INTERFACE_URI_LIST, params,
		new RequestCallBack<String>() {
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				try {
					String rs = responseInfo.result;
					Map map = FastjsonUtil.json2Map(rs);
					int code = Integer.parseInt(String.valueOf(map.get("code")));
					if (code != 200) {
						//请求失败
						handler.sendEmptyMessage(Constants.FAILURE);
						return;
					}
					PageResult page = FastjsonUtil.deserialize(
							map.get("data").toString(), PageResult.class);
					Message message = new Message();
					Bundle bundle = new Bundle();
					bundle.putSerializable("pageResult", page);
					message.what = Constants.SUCCESS;
					message.setData(bundle);
					handler.sendMessage(message);
				} catch (Exception e) {
					handler.sendEmptyMessage(Constants.FAILURE);
				}
			}
			@Override
			public void onFailure(HttpException error, String msg) {
				handler.sendEmptyMessage(Constants.FAILURE);
			}
		});
}
 
Example 14
Source File: JokeServiceImpl.java    From QiQuYing with Apache License 2.0 4 votes vote down vote up
@Override
public void refush(final Handler handler, int type, int newOrHotFlag, int count) {
	HttpUtils http = new HttpUtils();
	http.configDefaultHttpCacheExpiry(0); //缓存超期时间0分钟
	http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
	RequestParams params = new RequestParams();
	params.addQueryStringParameter("type", String.valueOf(type));
	params.addQueryStringParameter("newOrHotFlag", String.valueOf(newOrHotFlag));
	params.addQueryStringParameter("count", String.valueOf(count));
	http.send(HttpRequest.HttpMethod.GET,
		RcpUri.INTERFACE_URI_LIST, params,
		new RequestCallBack<String>() {
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				try {
					String rs = responseInfo.result;
					Map map = FastjsonUtil.json2Map(rs);
					int code = Integer.parseInt(String.valueOf(map.get("code")));
					if (code != 200) {
						//请求失败
						handler.sendEmptyMessage(Constants.FAILURE);
						return;
					}
					PageResult page = FastjsonUtil.deserialize(
							map.get("data").toString(), PageResult.class);
					Message message = new Message();
					Bundle bundle = new Bundle();
					bundle.putSerializable("pageResult", page);
					message.what = Constants.SUCCESS_1;
					message.setData(bundle);
					handler.sendMessage(message);
				} catch (Exception e) {
					handler.sendEmptyMessage(Constants.FAILURE);
				}
			}
			@Override
			public void onFailure(HttpException error, String msg) {
				handler.sendEmptyMessage(Constants.FAILURE);
			}
		});
}
 
Example 15
Source File: UserServiceImpl.java    From QiQuYing with Apache License 2.0 4 votes vote down vote up
@Override
public void regist(final Handler handler, String email, String password) {
	HttpUtils http = new HttpUtils();
	http.configDefaultHttpCacheExpiry(1000 * 60 * 10); //缓存超期时间10分钟
	http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
	RequestParams params = new RequestParams();
	params.addQueryStringParameter("userName", email);
	params.addQueryStringParameter("password", password);
	http.send(HttpRequest.HttpMethod.POST,
		RcpUri.INTERFACE_URI_REGIST, params,
		new RequestCallBack<String>() {
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				String rs = responseInfo.result;
				Map map = FastjsonUtil.json2Map(rs);
				int code = Integer.parseInt(String.valueOf(map.get("code")));
				if (code != 200) {
					//请求失败
					handler.sendEmptyMessage(Constants.FAILURE_1);
					Log.e(TAG, "regist failure");
					if(code == 502) {  //用户名存在
						ToastUtils.showMessage(mContext, R.string.phone_exists);
					}
					if(code == 504) {  //注册失败
						ToastUtils.showMessage(mContext, R.string.regist_fail);
					}
					return;
				}
				Log.e(TAG, "regist success");
				User user = FastjsonUtil.deserialize(
						map.get("data").toString(), User.class);
				Message message = new Message();
				Bundle bundle = new Bundle();
				bundle.putSerializable("user", user);
				message.what = Constants.SUCCESS_1;
				message.setData(bundle);
				handler.sendMessage(message);
			}
			@Override
			public void onFailure(HttpException error, String msg) {
				Log.e(TAG, "regist failure", error);
				handler.sendEmptyMessage(Constants.FAILURE_1);
				if(!HttpUtil.isNetworkAvailable(mContext)) {
					ToastUtils.showMessage(mContext, R.string.no_net);
				} else {
					ToastUtils.showMessage(mContext, R.string.regist_fail);
				}
			}
		});
}
 
Example 16
Source File: JokeServiceImpl.java    From QiQuYing with Apache License 2.0 4 votes vote down vote up
@Override
public void addComment(final Handler handler, Integer jokeId, String content) {
	if(App.currentUser == null || Util.isEmpty(content)) {
		return;
	}
	HttpUtils http = new HttpUtils();
	http.configDefaultHttpCacheExpiry(1000 * 60 * 10); //缓存超期时间10分钟
	http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
	RequestParams params = new RequestParams();
	params.addQueryStringParameter("jokeId", String.valueOf(jokeId));
	params.addQueryStringParameter("userId", String.valueOf(App.currentUser.getId()));
	params.addQueryStringParameter("userPortrait", App.currentUser.getPortraitUrl());
	try {
		params.addQueryStringParameter("userNick", 
				URLEncoder.encode(App.currentUser.getUserNike(), "UTF-8"));
		params.addQueryStringParameter("content", 
				URLEncoder.encode(content, "UTF-8"));
	} catch (UnsupportedEncodingException e) {
		e.printStackTrace();
	}
	http.send(HttpRequest.HttpMethod.POST,
		RcpUri.INTERFACE_URI_COMMENT, params,
		new RequestCallBack<String>() {
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				String rs = responseInfo.result;
				Map map = FastjsonUtil.json2Map(rs);
				int code = Integer.parseInt(String.valueOf(map.get("code")));
				if (code != 200) {
					//请求失败
					Log.e(TAG, "comment failure");
					ToastUtils.showMessage(mContext, R.string.comment_fail);
					handler.sendEmptyMessage(Constants.FAILURE_1);
					return;
				}
				Log.e(TAG, "comment success");
				handler.sendEmptyMessage(Constants.SUCCESS_1);
			}
			@Override
			public void onFailure(HttpException error, String msg) {
				Log.e(TAG, "comment failure", error);
				handler.sendEmptyMessage(Constants.FAILURE_1);
				if(!HttpUtil.isNetworkAvailable(mContext)) {
					ToastUtils.showMessage(mContext, R.string.no_net);
				} else {
					ToastUtils.showMessage(mContext, R.string.comment_fail);
				}
			}
		});
}
 
Example 17
Source File: UserServiceImpl.java    From QiQuYing with Apache License 2.0 4 votes vote down vote up
@Override
public void addSinaUser(final Handler handler, String uid, String portraitUrl,
		String nickName) {
	HttpUtils http = new HttpUtils();
	http.configDefaultHttpCacheExpiry(1000 * 60 * 10); //缓存超期时间10分钟
	http.configTimeout(Constants.REQUEST_TIME_OUT);  //设置超时时间
	RequestParams params = new RequestParams();
	params.addQueryStringParameter("uid", uid);
	params.addQueryStringParameter("portraitUrl", portraitUrl);
	try {
		params.addQueryStringParameter("nickName", URLEncoder.encode(nickName, "UTF-8"));
	} catch (UnsupportedEncodingException e) {
		e.printStackTrace();
	}
	http.send(HttpRequest.HttpMethod.POST,
		RcpUri.INTERFACE_URI_ADD_SINA_USER, params,
		new RequestCallBack<String>() {
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				String rs = responseInfo.result;
				Map map = FastjsonUtil.json2Map(rs);
				int code = Integer.parseInt(String.valueOf(map.get("code")));
				if (code != 200) {
					//请求失败
					if(handler != null) {
						handler.sendEmptyMessage(Constants.FAILURE_2);
					}
					Log.e(TAG, "save user failure");
					return;
				}
				Log.e(TAG, "save user success");
				User user = FastjsonUtil.deserialize(
						map.get("data").toString(), User.class);
				if(handler != null) {
					Message message = new Message();
					Bundle bundle = new Bundle();
					bundle.putSerializable("user", user);
					message.what = Constants.SUCCESS_2;
					message.setData(bundle);
					handler.sendMessage(message);
				} else {
					App.currentUser = user;
					App.getInstance().getSpUtil().putObject("user", user);
				}
			}
			@Override
			public void onFailure(HttpException error, String msg) {
				Log.e(TAG, "save user failure", error);
				if(handler != null) {
					handler.sendEmptyMessage(Constants.FAILURE_2);
				}
			}
		});
}