//
工具类解析json
///
import java.io.IOException;
}
///
mainactivity
///
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;
import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.location.LocationClientOption.LocationMode;
public class MainActivity extends Activity {
private LocationClient mLocationClient = null;
private BDLocationListener myListener = new MyLocationListener();
private TextView cityName;
private ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mLocationClient = new LocationClient(getApplicationContext());
mLocationClient.registerLocationListener(myListener); // 注册监听函数
initLocation();
mLocationClient.start();
}
private void initLocation() {
LocationClientOption option = new LocationClientOption();
option.setLocationMode(LocationMode.Hight_Accuracy);// 可选,默认高精度,设置定位模式,高精度,低功耗,仅设备
option.setCoorType("bd09ll");// 可选,默认gcj02,设置返回的定位结果坐标系
int span = 1000;
option.setScanSpan(span);// 可选,默认0,即仅定位一次,设置发起定位请求的间隔需要大于等于1000ms才是有效的
option.setIsNeedAddress(true);// 可选,设置是否需要地址信息,默认不需要
option.setOpenGps(true);// 可选,默认false,设置是否使用gps
option.setLocationNotify(true);// 可选,默认false,设置是否当gps有效时按照1S1次频率输出GPS结果
option.setIsNeedLocationDescribe(true);// 可选,默认false,设置是否需要位置语义化结果,可以在BDLocation.getLocationDescribe里得到,结果类似于“在北京天安门附近”
option.setIsNeedLocationPoiList(true);// 可选,默认false,设置是否需要POI结果,可以在BDLocation.getPoiList里得到
option.setIgnoreKillProcess(false);// 可选,默认true,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop的时候杀死这个进程,默认不杀死
option.SetIgnoreCacheException(false);// 可选,默认false,设置是否收集CRASH信息,默认收集
option.setEnableSimulateGps(false);// 可选,默认false,设置是否需要过滤gps仿真结果,默认需要
mLocationClient.setLocOption(option);
cityName = (TextView) findViewById(R.id.cityName);
listView = (ListView) findViewById(R.id.listView);
MyBaseAdapter1 adapter1 = new MyBaseAdapter1(getApplicationContext());
// 设置适配器
listView.setAdapter(adapter1);
cityName.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// 跳转到房源列表
startActivity(new Intent(MainActivity.this, InfoActivity.class));
}
});
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView> arg0, View arg1, int arg2,
long arg3) {
// 跳转到房源列表
startActivity(new Intent(MainActivity.this, InfoActivity.class));
}
});
}
// 实现BDLocationListener
public class MyLocationListener implements BDLocationListener {
@Override
public void onReceiveLocation(BDLocation location) {
// 展示定位城市
cityName.setText(location.getCity());
}
}
}
//////////////
infoactivity
/////////////////////////
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ListView;
import com.example.yuekao_last.bean.MyResult;
import com.example.yuekao_last.bean.Rows;
import com.example.yuekao_last.utils.NewWorkUtils;
import com.google.gson.Gson;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener2;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
public class InfoActivity extends Activity {
private List
int p = 1;
private MyBaseAdapter myBaseAdapter;
Handler handler = new Handler() {
public void handleMessage(android.os.Message msg) {
switch (msg.what) {
case 1:
rows = (List
myBaseAdapter = new MyBaseAdapter(context, rows);
pulltorefresh.setAdapter(myBaseAdapter);
break;
case 2:
List
rows.addAll(0, rows2);
myBaseAdapter.notifyDataSetChanged();
pulltorefresh.onRefreshComplete();
break;
case 3:
List
rows.addAll(rows3);
myBaseAdapter.notifyDataSetChanged();
pulltorefresh.onRefreshComplete();
break;
default:
break;
}
};
};
private PullToRefreshListView pulltorefresh;
private Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_info);
context = getApplicationContext();
init();
}
private void init() {
// TODO Auto-generated method stub
pulltorefresh = (PullToRefreshListView) findViewById(R.id.pulltorefresh);
pulltorefresh.setMode(Mode.BOTH);
myData(1, 0);
pulltorefresh.setOnRefreshListener(new OnRefreshListener2
@Override
public void onPullDownToRefresh(
PullToRefreshBase
myData(2, 0);
}
@Override
public void onPullUpToRefresh(
PullToRefreshBase
myData(3, p++);
}
});
}
private void myData(final int what, final int id) {
new Thread() {
public void run() {
String data = NewWorkUtils.getData(id);
Gson gson = new Gson();
MyResult myResult = gson.fromJson(data, MyResult.class);
List
handler.sendMessage(handler.obtainMessage(what, rows));
};
}.start();
}
}
/////////////////////////////////
清单文件配置
/////////////////////////
android:value="dFWiYuwGO23O1O1wxkqLW4wjiUuTBEX0" />
android:enabled="true"
android:process=":remote" >
////////////////////
imageLoader的简单加入
/////////////////////
import java.io.File;
import android.app.Application;
import android.graphics.Bitmap.Config;
import android.os.Environment;
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.nostra13.universalimageloader.core.decode.BaseImageDecoder;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
public class MyApplication extends Application{
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
//sdcard的路径
String sdPath=Environment.getExternalStorageDirectory().getPath();
//自定义的方式
ImageLoaderConfiguration configuration=new ImageLoaderConfiguration.Builder(this)
.memoryCacheExtraOptions(480, 800)//内存缓存文件的最大长宽
.discCacheExtraOptions(480, 800, null)//本地缓存的详细信息
.threadPoolSize(3)//线程池内加载的数量
.threadPriority(Thread.NORM_PRIORITY-2)//设置当前线程的优先级
.tasksProcessingOrder(QueueProcessingType.FIFO)//设置任务的处理顺序
.denyCacheImageMultipleSizesInMemory()//防止内存中图片重复
.memoryCache(new LruMemoryCache(2*1024*1024))//设置自己的内存缓存大小 2M
.memoryCacheSize(2*1024*1024)
.memoryCacheSizePercentage(13)//内存缓存百分比
.discCache(new UnlimitedDiscCache(new File(sdPath+"/huang/image1")))//设置缓存的图片在sdcard中的位置
.discCacheSize(50*1024*1024)//硬盘缓存大小 50M
.discCacheFileCount(100)//硬盘缓存文件个数
.discCacheFileNameGenerator(new Md5FileNameGenerator())//md5加密的方式,或new HashCodeFileNameGenerator()
.imageDownloader(new BaseImageDownloader(this))
.imageDecoder(new BaseImageDecoder(true))//图片解码
.defaultDisplayImageOptions(getOption())//是否使用默认的图片加载配置,null表示不使用
.writeDebugLogs()
.build();
//初始化
ImageLoader.getInstance().init(configuration);
}
/*
* 设置option
*/
public static DisplayImageOptions getOption(){
DisplayImageOptions option=new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.ic_launcher)//设置图片下载期间显示的图片
.resetViewBeforeLoading(false)//设置图片在加载前是否重置、复位
//.delayBeforeLoading(1000)//下载前的延迟时间
.cacheInMemory(true)//设置下载的图片是否缓存在内存中
.cacheOnDisk(true)//设置下载的图片是否缓存在sd卡中
.considerExifParams(false)//思考可交换的参数
.imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2)//设置图片的显示比例
.bitmapConfig(Config.RGB_565)//设置图片的解码类型
.displayer(new RoundedBitmapDisplayer(40))//设置图片的圆角半径
.displayer(new FadeInBitmapDisplayer(3000))//设置图片显示的透明度过程的时间
.build();
return option;
}
}