- Email: wwwcenjin1314@163.com
//1.设置主页面<br>
setContentView(R.layout.activity_main);
//2.设置左侧菜单
setBehindContentView(R.layout.activity_leftmenu);
//3.设置右侧菜单
SlidingMenu slidingMenu = getSlidingMenu();
slidingMenu.setSecondaryMenu(R.layout.activity_rightmenu);//设置右侧菜单
//4.设置显示的模式:左侧菜单+主页,左侧菜单+主页面+右侧菜单;主页面+右侧菜单
slidingMenu.setMode(SlidingMenu.LEFT);
//5.设置滑动模式:滑动边缘,全屏滑动,不可以滑动
slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
//6.设置主页占据的宽度
slidingMenu.setBehindOffset(DensityUtil.dip2px(MainActivity.this,200));
......
......
2.1 xUntils3
2.1.1在Application中初始化XUntils3
x.Ext.setDebug(true);
x.Ext.init(this);
2.1.2 使用xUntils3做联网请求
private void getDataFromInternet() {
RequestParams requestParams = new RequestParams(Constant.NEWS_URL);
x.http().get(requestParams, new Callback.CommonCallback<String>() {
@Override
public void onSuccess(String result) {
long endTime = SystemClock.uptimeMillis();
long passTime = endTime - startTime ;
LogUtil.e("xUntil3的请求时间 " + passTime);
LogUtil.e("成功 " + result);
//缓存数据
CacheUntil.putString(context, Constant.NEWS_URL, result);
//适配器
processData(result);
}
......
......
2.2使用volley做联网请求
private void getDataFromInternetByVolley() {
//请求队列
//RequestQueue requestQueue = Volley.newRequestQueue(context);
//String请求
StringRequest stringRequest = new StringRequest(Request.Method.GET, Constant.NEWS_URL, new Response.Listener<String>() {
@Override
public void onResponse(String s) {
long endTime = SystemClock.uptimeMillis();
long passTime = endTime - startTime ;
LogUtil.e("volley的请求时间 " + passTime);
LogUtil.e("volley成功 " + s);
//缓存数据
CacheUntil.putString(context, Constant.NEWS_URL, s);
//适配器
processData(s);
}
}, new Response.ErrorListener() {
......
......
private HomePagerBean parsedJson(String json) {
Gson gson = new Gson();
HomePagerBean homePagerBean = gson.fromJson(json, HomePagerBean.class);
//HomePagerBean2 homePagerBean2 = gson.fromJson(json, HomePagerBean2.class);
return homePagerBean;
}
......
......
//ViewPager和TabPageIndicator关联
tabPageIndicator.setViewPager(viewPager);
- 缓存文本数据
SharedPreferences sp= context.getSharedPreferences("chenjin" , context.MODE_PRIVATE);
sp.edit().putString(key, value).commit();
- 图片三级缓存
//1.从内存中获取图片
if(memoryCacheUtil != null){
Bitmap bitmap = memoryCacheUtil.getBitmapFromUrl(imageUrl);
if(bitmap != null){
LogUtil.e("内存图片加载成功++" + position);
return bitmap;
}
}
//2.从本地中获取图片
if(localCacheUtil != null){
Bitmap bitmap = localCacheUtil.getBitmapFromUrl(imageUrl);
if(bitmap != null){
LogUtil.e("本地图片加载成功++" + position);
return bitmap;
}
}
//3.从网络中获取图片
netCacheUtil.getBitmapFromNet(imageUrl, position);
return null;
......
......
private void getDataFromNet() {
prePosition = 0;
RequestParams requestParams = new RequestParams(url);
requestParams.setConnectTimeout(6000);
x.http().get(requestParams, new Callback.CommonCallback<String>() {
@Override
public void onSuccess(String result) {
LogUtil.e("联网成功"+childBean.getTitle() + result);
//缓存数据
CacheUntil.putString(context, url, result);
//解析和处理显示数据
processData(result);
//隐藏下拉刷新控件,并更新时间.数据
list_item_tabdetail.onRefreshFinish(true);
}
......
......
private void getMoreDataFromNet() {
RequestParams requestParams = new RequestParams(moreUrl);
requestParams.setConnectTimeout(6000);
x.http().get(requestParams, new Callback.CommonCallback<String>() {
@Override
public void onSuccess(String result) {
LogUtil.e("加载更多联网成功 ++"+result);
list_item_tabdetail.onRefreshFinish(false);
//为true,才去解析数据.要放在前面
isLoadMOre = true;
//解析数据
processData(result);
}
......
......
//跳转到新闻浏览页面
Intent intent = new Intent(context, NewsDetailActivity.class);
intent.putExtra("url", Constant.BASE_URL + newsBean.getUrl());
context.startActivity(intent);
......
......
private void showChangeTextSizeDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("设置文字大小");
String[] items = new String[]{"超大字体","大字体","正常字体","小字体","超小字体"};
builder.setSingleChoiceItems(items, realSize, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
tempSize = which;
}
});
builder.setNegativeButton("取消",null);
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//根据位置得到对应的数据
PhotosDetailPagerBean.DataBean.NewsBean newsBean = news.get(position);
String imageUrl = Constant.BASE_URL + newsBean.getLargeimage();
Intent intent = new Intent(context, ShowImageActivity.class);
intent.putExtra("url",imageUrl);
context.startActivity(intent);
}
final PhotoViewAttacher attacher = new PhotoViewAttacher(photoView);
Picasso.with(this)
.load(url)
.into(photoView, new Callback() {
@Override
public void onSuccess() {
attacher.update();
}
@Override
public void onError() {
}
});
- 图片三级缓存中的本地缓存 失败
- 用drawerlayout替换slidingmenu
- 点击底部小鸡图片使其能跃出RadioButton
- 屏幕适配 follow2 follow3
- android版本适配
- 分享功能
- (windows)在cmd中运行 ipconfig 查看ip地址并在Constant类中修改
- 点这里
- SlidingMenu: https://github.com/jfeinstein10/SlidingMenu
- xUtils: https://github.com/wyouflf/xUtils3
- gson:https://github.com/google/gson
- ViewPageIndicator:https://github.com/JakeWharton/ViewPagerIndicator
- Android-PullToRefresh:https://github.com/chrisbanes/Android-PullToRefresh
- Volley:https://android.googlesource.com/platform/frameworks/volley
- glide:https://github.com/bumptech/glide
- picasso:https://github.com/square/picasso
- 极光推送:https://www.jiguang.cn/
- Android-Universal-Image-Loader:https://github.com/nostra13/Android-Universal-Image-Loader
- PhotoView:https://github.com/chrisbanes/PhotoView
- okhttp:https://github.com/square/okhttp
- okhttputils:https://github.com/hongyangAndroid/okhttputils