asasa

package com.jleo;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class DisplayCurrentFixAction extends Action {
private TextView utc;
private TextView currentLatitude;
private TextView currentLontitude;
private TextView direction;
private TextView speed;
private Button updateBtn;
private Button sendBtn;
private LocationManager locationManager;

private LocationListener locationlisterner;
private Location currentLocation;
protected static final int DIALOG_INTERACT = 0;

@Override
public void apply(final Activity activity2) {

}

public void updateLocationInfo(Location location) {
if (location == null) {
alert(R.string.location_not_available);
} else {
utc.setText(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
.format(new Date(location.getTime())));
currentLatitude.setText(String.valueOf(location.getLatitude()));
currentLontitude.setText(String.valueOf(location.getLongitude()));
if (location.hasBearing()) {
direction.setText(String.valueOf(location.getBearing()));
} else {
direction.setText(R.string.lbl_unavailable);
}
if (location.hasSpeed()) {
speed.setText(String.valueOf(String
.valueOf(location.getSpeed() * 3.6))
+ getApplicationContext().getString(
R.string.lbl_speed_unit));
} else {
speed.setText(R.string.lbl_unavailable);
}
}
}

@Override
void apply() {
updateBtn = findViewById(R.id.update,Button.class);
sendBtn = findViewById(R.id.send,Button.class);
utc = findViewById(R.id.val_UTC,TextView.class);
currentLatitude = findViewById(R.id.val_current_latitude,TextView.class);
currentLontitude = findViewById(R.id.val_current_longitude,TextView.class);
direction = findViewById(R.id.val_direction, TextView.class);
speed = findViewById(R.id.val_speed, TextView.class);
locationlisterner = new TraceMeLocationListener(this);
locationManager = getSystemService(Activity.LOCATION_SERVICE, LocationManager.class);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
0, locationlisterner);
updateBtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Location location = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
updateLocationInfo(location);
}

});
sendBtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Location location = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
updateLocationInfo(location);
if (location != null) {
currentLocation = location;
showDialog(DIALOG_INTERACT);
}

}
});
}


@Override
public int getViewId() {
return R.layout.main;
}

@Override
public void unapply(Activity activity) {
this.locationManager.removeUpdates(locationlisterner);
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值