常用控件依赖
apache(HttpClient)依赖 useLibrary 'org.apache.http.legacy' Tablayout的依赖 implementation 'com.android.support:design:26.+' PullToRefreshListView的依赖 compile 'com.github.userswlwork:pull-to-refresh:1.0.0' =============================================================
常用控件布局
Tablayout布局设置 app:tabGravity="center" app:tabIndicatorColor="@color/colorAccent" app:tabMode="scrollable" app:tabSelectedTextColor="@color/colorPrimaryDark" app:tabTextColor="@color/colorPrimary" ============================================================ PullToRefreshListView布局 <com.handmark.pulltorefresh.library.PullToRefreshListView> ptr:ptrDrawable="@drawable/default_ptr_flip" ptr:ptrAnimationStyle="flip" ptr:ptrHeaderBackground="#383838" ptr:ptrHeaderTextColor="#FFFFFF" <com.handmark.pulltorefresh.library.PullToRefreshListView/>
Applaction工具类
//自定义sd卡缓存目录
File file=new File(Environment.getExternalStorageDirectory()+"/images");
//初始化,,全局配置applction
ImageLoaderConfiguration configuration=new ImageLoaderConfiguration.Builder(this)
.memoryCacheExtraOptions(400, 700)//缓存图片最大的长和宽
.threadPoolSize(3)//线程池的数量
.threadPriority(4)
.memoryCacheSize(20*1024*1024)//设置内存缓存区大小
.diskCacheSize(80*1024*1024)//设置sd卡缓存区大小
.diskCache(new UnlimitedDiscCache(file))//自定义sd卡缓存目录
.writeDebugLogs()//打印日志内容
.diskCacheFileNameGenerator(new Md5FileNameGenerator())//给缓存的文件名进行md5加密处理
.build();
ImageLoader.getInstance().init(configuration);
适配器中
DisplayImageOptions options = new DisplayImageOptions.Builder()
.cacheInMemory(true)//使用内存缓存
.cacheOnDisk(true)//使用磁盘缓存
.showImageOnLoading(R.mipmap.ic_launcher)//设置正在下载的图片
.showImageForEmptyUri(R.mipmap.ic_launcher)//url为空或请求的资源不存在时
.showImageOnFail(R.mipmap.ic_launcher)//下载失败时显示的图片
.bitmapConfig(Bitmap.Config.RGB_565)//设置图片色彩模式 1px=2字节
.imageScaleType(ImageScaleType.EXACTLY)//设置图片的缩放模式
.displayer(new RoundedBitmapDisplayer(100))//设置圆角 30代表半径 自定义
.build();
判断网络
//判断有无网络的方法
public static boolean isConn(Context context){
//1.得到系统服务
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
//2.得到网络信息类对象-需要添加权限
NetworkInfo info = manager.getActiveNetworkInfo();
//3.进行判断
if(info!=null && info.isAvailable()){//已经连接网络
return true;
}else{
return false;
}
}
//如果没有网络的情况下,弹出一个对话框,打开设置页面
public static void openNetDialog(final Context context){
AlertDialog.Builder builder=new AlertDialog.Builder(context);
builder.setTitle("提示");
builder.setMessage("没有网络,是否进行设置?");
builder.setPositiveButton("设置", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//跳转到系统设置页面-隐士跳转
Intent intent = null;
// 先判断当前系统版本
if(android.os.Build.VERSION.SDK_INT > 10){ // 3.0以上
intent = new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS);
}else{
intent = new Intent();
intent.setClassName("com.android.settings", "com.android.settings.WirelessSettings");
}
context.startActivity(intent);
}
});
builder.setNegativeButton("取消",null);
AlertDialog dialog = builder.create();
dialog.show();
}