一些工具类
以下是一些工具类和一些位置放的不太好的类,有点就没改了。写的不太好还请大家多指教。
package com.tmall.net;
import org.apache.http.Header;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.tmall.view.base.BaseApplication;
public abstract class CommonHttpHandler extends AsyncHttpResponseHandler {
public abstract void success(int arg0, Header[] arg1, byte[] bytes);
@Override
public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) {
// 没网 404 500
// 回到了主线程 main
String msg = "";
if (404 == arg0)// 服务器error
{
msg = "服务器繁忙";
} else if (0 == arg0)// 手机网络问题,请求超时
{
msg = "手机网络问题,请求超时";
} else {
String str = new String(arg2);
msg += "Header[]:" + arg1 == null ? "" : arg1.toString() + str
+ "byte[]:" + arg2 == null ? "" : new String(arg2);
}
BaseApplication.makeText(msg);
}
@Override
public void onSuccess(int arg0, Header[] arg1, byte[] bytes) {
success(arg0, arg1, bytes);
}
}
package com.tmall.net;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.RequestParams;
public class HttpUtil {
public static final String BASE_IP = "123.207.27.202";
public static final String BASE_URL = "http://" + BASE_IP + ":8080/Tmall/";
private static AsyncHttpClient client;
private HttpUtil() {
}
static {
client = new AsyncHttpClient();
}
public static void post(String url, RequestParams params,
CommonHttpHandler commonHandler) {
client.post(url, params, commonHandler);
}
}
package com.tmall.common;
public class CommonResult {
public static String userName;
}
package com.tmall.logic;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import com.example.tmall.R;
import com.tmall.view.HomeFragment;
public class MyPageChangeListener implements OnPageChangeListener {
private View[] views;
private HomeFragment fragment;
public MyPageChangeListener(View[] views, HomeFragment fragment) {
this.views = views;
this.fragment = fragment;
}
@Override
public void onPageScrollStateChanged(int state) {
switch (state) {
case 1:// 手势滑动
fragment.setAutoPlay(false);
break;
case 2:// 界面切换
fragment.setAutoPlay(true);
break;
case 0:// 滑动结束,即切换完毕或加载完毕
if (fragment.getHome_vp().getCurrentItem() == fragment.getHome_vp()
.getAdapter().getCount() - 1
&& !fragment.isAutoPlay()) {
fragment.getHome_vp().setCurrentItem(0);
}
// 当前为第一张,此时从左向右滑,则切换到最后一张
else if (fragment.getHome_vp().getCurrentItem() == 0
&& !fragment.isAutoPlay()) {
fragment.getHome_vp().setCurrentItem(
fragment.getHome_vp().getAdapter().getCount() - 1);
}
break;
default:
break;
}
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
@Override
public void onPageSelected(int position) {
fragment.setPagePosition(position);
for (int i = 0; i < views.length; i++) {
if (position == i) {
views[i].setBackgroundResource(R.drawable.page_shapes_selector);
} else {
views[i].setBackgroundResource(R.drawable.page_shapes_normal);
}
}
}
}