package com.jqyd.android.module.lbs.test;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import com.jqyd.android.module.lbs.LocationClient;
import com.jqyd.android.module.lbs.R;
import com.jqyd.android.module.lbs.Interface.ILocationListener;
import com.jqyd.android.module.lbs.bean.LocationInfo;
import com.jqyd.android.module.lbs.bean.LocationTimerTask;
import com.jqyd.android.module.lbs.util.JqydDateUtil;
public class OneActivity extends Activity {
TextView tv;
TextView tv1;
Button b,b1;
ProgressDialog pd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_one);
tv = (TextView) findViewById(R.id.tv);
tv1 = (TextView) findViewById(R.id.tv1);
b=(Button) findViewById(R.id.b1);
b1=(Button) findViewById(R.id.b2);
final StringBuffer stringBuffer = new StringBuffer();
final Handler handler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {
if(pd!=null){pd.dismiss();}
switch (msg.what) {
case 0:
LocationInfo bean = (LocationInfo) msg.obj;
stringBuffer.append("bean:"+bean.getLat()+":"+bean.getLon());
tv.setText(stringBuffer.toString());
break;
case 2:
int i = (Integer) msg.obj;
if(i==2){
tv1.setText("GPS");
}else if(i==1){
tv1.setText("baidu");
}else{
tv1.setText("失败");
}
break;
default:
break;
}
return false;
}
});
@SuppressWarnings("unused")
long id = Thread.currentThread().getId();
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
pd = new ProgressDialog(OneActivity.this);
pd.setMessage("定位中");
pd.show();
LocationClient client = new LocationClient(OneActivity.this);
// client.request(new ILocationListener() {
//
// @Override
// public void onReceiveLocInfo(int locType, LocationInfo bean) {
// handler.sendMessage(Message.obtain(handler, 2, locType));
// handler.sendMessage(Message.obtain(handler, 0, bean));
// }
// });
// client.request(2, new ILocationListener() {
//
// @Override
// public void onReceiveLocInfo(int locType, LocationInfo bean) {
// // TODO Auto-generated method stub
// handler.sendMessage(Message.obtain(handler, 2, locType));
// handler.sendMessage(Message.obtain(handler, 0, bean));
// }
// });
// //对Task属性赋值---比如开始时间,结束时间等
LocationTimerTask task = new LocationTimerTask();
task.setLocationWay(1);
task.setStartTime(JqydDateUtil.timeToLong("9:00"));
task.setPeriod(3);
task.setEndTime(JqydDateUtil.timeToLong("20:00"));
//--开始定时定位任务
client.regTimerTask(task, TestService.class);
}
});
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//停止定时定位任务
LocationClient client = new LocationClient(OneActivity.this);
client.deleteTimerTask(TestService.class);
}
});
}
}