package com.example.zhuixing;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLConnection;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity implements SensorEventListener {
// 主程序声明区
private String strURL = "http://www.celestrak.com/NORAD/elements/amateur.txt";
private ImageView iv_canvas;
private Bitmap baseBitmap;
private Canvas canvas;
private Paint paint0;
private Paint paint1;
private SensorManager aSensorManager;
private SensorManager mSensorManager;
// 需要两个Sensor
private Sensor accelerometer; // 加速度传感器
private Sensor magnetic; // 地磁场传感器
private TextView text1;
private TextView text2;
private TextView text3;
String xlsat;// 卫星名
String xingli0 = "LILACSAT 2";// 星历名称
String xingli1 = "1 40908U 15049K 16263.84597852 .00001065 00000-0 64316-4 0 9992";// 第1行星历
String xingli2 = "2 40908 97.4618 268.7280 0017983 67.1962 293.1166 15.12705779 55293";// 第2行星历
double yhjd = 115.0 / 180 * Math.PI;// 用户经度
double yhwd = 38.5 / 180 * Math.PI;// 用户纬度
double haiba = 50;// 海拔
double cipianjiao = -5;// 磁偏角
double xxpl0 = 437.2;/// 下行频率
double sxpl0 = 144.35;// 上行频率
// ****************************************************************
String timep;// 确定平近点角的时间
double qingjiao;// 轨道倾角
double chijing;// 升交点赤经
double pianxinlv; // 轨道偏心率
double jddfj;// 近地点幅角
double pjdj;// 平近点角
double mrrxqs; // 每日绕行圈数
double juli;// 卫星到用户的距离
double xxpl1;// 下行频率 多普勒
double sxpl1;// 上行频率 多普勒
long timeN0;// 时间基准,计算距移率用
float[] accelerometerValues = new float[3];
float[] magneticFieldValues = new float[3];
float[] accelerometerValuesA = new float[3];
float[] magneticFieldValuesA = new float[3];
float[] Azmvalues = new float[3];
float[] R1 = new float[9];
String xiaoxi = "...";
@Override
// 程序初始化
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 主程序运行开始
Update();// ***************************************************************
text1 = (TextView) findViewById(R.id.textView1);
text2 = (TextView) findViewById(R.id.textView2);
text3 = (TextView) findViewById(R.id.textView3);
iv_canvas = (ImageView) findViewById(R.id.imageView1);
// 初始化一个画笔
paint0 = new Paint();
paint0.setStrokeWidth(2);
paint0.setColor(Color.BLACK);
paint0.setStyle(Paint.Style.STROKE);
paint1 = new Paint();
paint1.setStrokeWidth(2);
paint1.setColor(Color.RED);
paint1.setStyle(Paint.Style.FILL);
// canvas.drawLine(1, 1, 100, 100, paint);
// 实例化传感器管理者
aSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
accelerometer = aSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
magnetic = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
juli = 0; // 用户到卫星距离
timeN0 = 0; // 计算距移率的基准
/*
* yhjd = 115.0 / 180 * Math.PI; yhwd = 38.5 / 180 * Math.PI; cipianjiao
* = -5; xxpl0 = 437.2; sxpl0 = 144.35; timep = "16242.81038550";
* qingjiao = 97.4613 / 180 * Math.PI;// 轨道倾角 chijing = 248.1546 / 180 *
* Math.PI;// 升交点赤经 pianxinlv = 0.0017609;// 轨道偏心率 jddfj = 133.3891 /
* 180 * Math.PI;// 近地点幅角 pjdj = 226.8810 / 180 * Math.PI;// 平近点角 mrrxqs
* = 15.12660259;// 每日绕行圈数
*/
}
protected void onResume() {
// TODO Auto-generated method stub
// 注册监听
aSensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL);
mSensorManager.registerListener(this, magnetic, SensorManager.SENSOR_DELAY_NORMAL);
super.onResume();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
// 解除注册
aSensorManager.unregisterListener(this);
mSensorManager.unregisterListener(this);
super.onPause();
}
public void onSensorChanged(SensorEvent event) {
// TODO Auto-generated method stub
synchronized (this) {
float[] tmpvalues = new float[3];
tmpvalues[0] = event.values[0];
tmpvalues[1] = event.values[1];
tmpvalues[2] = event.values[2];
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
accelerometerValues = tmpvalues;
}
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
magneticFieldValues = tmpvalues;
}
calculateOrientation();// 调用计算程序,每次传感器返回数据都调用。
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// TODO Auto-generated method stub
// 传感器精度变化时
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
// 创建目录菜单 弹出个settings
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
// 计算程序,核心代码
private void calculateOrientation() {
accelerometerValuesA[0] = (float) (accelerometerValuesA[0] * 0.9 + accelerometerValues[0] * 0.1);
accelerometerValuesA[1] = (float) (accelerometerValuesA[1] * 0.9 + accelerometerValues[1] * 0.1);
accelerometerValuesA[2] = (float) (accelerometerValuesA[2] * 0.9 + accelerometerValues[2] * 0.1);
magneticFieldValuesA[0] = (float) (magneticFieldValuesA[0] * 0.95 + magneticFieldValues[0] * 0.05);
magneticFieldValuesA[1] = (float) (magneticFieldValuesA[1] * 0.9 + magneticFieldValues[1] * 0.1);
magneticFieldValuesA[2] = (float) (magneticFieldValuesA[2] * 0.9 + magneticFieldValues[2] * 0.1);
// 滤波后显示10次平均值数据。
SensorManager.getRotationMatrix(R1, null, accelerometerValues, magneticFieldValues);
SensorManager.getOrientation(R1, Azmvalues);
// 要经过一次数据格式的转换,转换为度 加上磁偏角(cipianjiao_)。
Azmvalues[0] = Math.round(((float) Math.toDegrees(Azmvalues[0]) + 360 + cipianjiao) % 360);
Azmvalues[1] = Math.round(-1 * (float) Math.toDegrees(Azmvalues[1]));
Azmvalues[2] = (float) Math.toDegrees(Azmvalues[2]);
// =======================================================================
//
// 计算卫星数据的核心代码
// BI3OJW,2016-9
// 好像是没有bug了。需要关注UTC时间与当地时间的问题。
//
// =======================================================================
Date date = new Date();// 获取当前时间
SimpleDateFormat from = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String times = from.format(date); // 按设置时间格式
long timeN = date.getTime();// 获取当前时间
long timeNd = timeN - timeN0;// 计算时间差(和上一次计算时)用于距移率
timeN0 = timeN;
// 计算当前儒略历timeNow
double timeNow = (double) (timeN) / 1000 / 3600 / 24 + 2440587.5;
// timeNow=2457344.83898148;
// 计算平近点角时儒略历timeJ星历生成时。前两位为年份,后面为日期。
String nian = timep.substring(0, 2);
String ri = timep.substring(2);
int ye = Integer.valueOf(nian) + 2000;
int a = (int) (ye / 100);
int b = (int) (2 - a + a / 4);
// (星历生成时的)年份的儒略历直接+后面的日期(小数形式)
double timeJ = (int) (365.25 * (ye + 4716)) + (int) (30.6001 * 2) + 1 + b - 1524.5 + Double.valueOf(ri);
/// 轨道根数
double t = (timeJ - 2451545) / 36525;
double hengxingshi = 280.46061837 + 360.98564736629 * (timeJ - 2451545) + 0.000387933 * t * t
- t * t * t / 38710000;
double cfqjd = (360 - hengxingshi % 360) / 180 * Math.PI;// 春分圈地理经度, 弧度
double GM = 398603000000000.0;
double wxjsd = mrrxqs * 2 * Math.PI / 24 / 3600;// 卫星角速度, 弧度每秒
double banchangzhou = Math.pow(GM / wxjsd / wxjsd, 0.333333333333);// 半长轴
double dqbj = 6378137.0 + haiba;// 地球半径
double gjddsj = timeJ - pjdj / 2 / Math.PI / mrrxqs;// 过近地点时间
double sjcjdd = timeNow - gjddsj;// 时间差 过近地点
double sjcxl = timeNow - timeJ;// 时间差 星历
double jddfjbhl = 4.97 * Math.pow((dqbj / banchangzhou), 3.5) * (5 * Math.pow(Math.cos(qingjiao), 2) - 1)
/ Math.pow((1 - Math.pow(pianxinlv, 2)), 2);// 近地点幅角变化率
double xzjddfj = jddfj + sjcxl * jddfjbhl / 180 * Math.PI;// 修正后
// 的近地点幅角(弧度制)
double gjddhqs = (sjcjdd * mrrxqs) % 1;// 过近地点后圈数
double sspjdj = gjddhqs * Math.PI * 2;// 实时平近点角,弧度
// double pjdjE=Math.acos(
// (pianxinlv+Math.cos(sspjdj))/(1+pianxinlv*Math.cos(sspjdj))
// );//弧度
double zjdjS = 2 * Math.atan(Math.sqrt((1 + pianxinlv) / (1 - pianxinlv)) * Math.tan(sspjdj / 2));// 真近点角,弧度
double wxfj = (xzjddfj + zjdjS + 2 * Math.PI) % (2 * Math.PI);// 卫星幅角,弧度
double xiuzheng1 = 0;
if ((wxfj > 0.5 * Math.PI) & (wxfj < Math.PI))
xiuzheng1 = Math.PI;
if ((wxfj > Math.PI) & (wxfj < 1.5 * Math.PI))
xiuzheng1 = -1 * Math.PI;
double wxxzjdbl = Math.atan(Math.cos(qingjiao) * Math.tan(wxfj)) + xiuzheng1;// 卫星旋转经度变量
double gdpmjdl = -9.95 * Math.pow(dqbj / banchangzhou, 3.5) * Math.cos(qingjiao)
/ Math.pow(1 - pianxinlv * pianxinlv, 2) * Math.PI / 180;// 轨道平面进动率
double wxjd = ((chijing + cfqjd + wxxzjdbl - sjcxl * 360.98563 / 180 * Math.PI + sjcxl * gdpmjdl + Math.PI)
% (Math.PI * 2) + Math.PI * 2) % (Math.PI * 2) - Math.PI;
double wxwd = Math.asin(Math.sin(qingjiao) * Math.sin(wxfj));
double dxj = Math
.acos(Math.sin(yhwd) * Math.sin(wxwd) + Math.cos(yhwd) * Math.cos(wxwd) * Math.cos(yhjd - wxjd));// 地心角
double dxjlr = banchangzhou * (1 - pianxinlv * Math.cos(sspjdj));
double Elv = Math.atan((dxjlr * Math.cos(dxj) - dqbj) / dqbj / Math.sin(dxj));// 用户仰角,度数单位
double jdc = (wxjd - yhjd + 2 * Math.PI) % (2 * Math.PI);
double wdyz = yhwd * Math.cos(jdc);
double Azm = (Math.asin(Math.sin(jdc) * Math.sin((0.5 * Math.PI - wxwd)) / Math.sin(dxj)) + 2 * Math.PI)
% (2 * Math.PI);
if (wxwd < wdyz) {
Azm = (Math.PI * 3 - Azm) % (2 * Math.PI);
}
double juli0 = juli;// 上次计算的距离
juli = Math.sqrt(dqbj * dqbj + dxjlr * dxjlr - 2 * dqbj * dxjlr * Math.cos(dxj));
double jyl = (juli - juli0) / timeNd * 1000;// 距移率
double dplxs = 300000000 / (300000000 + jyl);
xxpl1 = xxpl0 * dplxs;
sxpl1 = 2 * sxpl0 - sxpl0 * dplxs;
// 计算完直接显示在text2里面。
text1.setText("当前时间:" + times);
text2.setText("手机方位角:" + Math.round(Azmvalues[0]) + "\t仰 角:" + Math.round(Azmvalues[1]) + "\n卫星方位角:"
+ Math.round(Azm * 180 / Math.PI) + "\t仰 角:" + Math.round(Elv * 180 / Math.PI) + "\n卫星经度:"
+ Math.round(wxjd * 180 / Math.PI) + "\t卫星纬度:" + Math.round(wxwd * 180 / Math.PI) + "\n用户经度:"
+ ((double)Math.round(yhjd * 18000 / Math.PI))/100 + "\t用户纬度:" + ((double)Math.round(yhwd * 18000 / Math.PI))/100 + "\n距离:"
+ Math.round(juli) + "\t距移率:" + (double) Math.round(jyl) + "\n下行频率:"
+ (double) Math.round(xxpl1 * 10000) / 10000 + "\t上行频率:" + (double) Math.round(sxpl1 * 10000) / 10000
+ "\n当前儒略历:" + timeNow);
text3.setText(xiaoxi);// 传递消息
// 画个瞄准镜显示目标x,目标y
long mubiaoX = Math.round(Azm * 180 / Math.PI) - Math.round(Azmvalues[0]);
if (mubiaoX < -180) {
mubiaoX = mubiaoX + 360;
}
if (mubiaoX > 180) {
mubiaoX = mubiaoX - 360;
}
long mubiaoY = Math.round(Azmvalues[1]) - Math.round(Elv * 180 / Math.PI);
if (baseBitmap != null) {
baseBitmap = Bitmap.createBitmap(150, 150, Bitmap.Config.ARGB_8888);
canvas = new Canvas(baseBitmap);
canvas.drawColor(Color.WHITE);
iv_canvas.setImageBitmap(baseBitmap);
}
if (baseBitmap == null) {
baseBitmap = Bitmap.createBitmap(150, 150, Bitmap.Config.ARGB_8888);
canvas = new Canvas(baseBitmap);
canvas.drawColor(Color.WHITE);
}
canvas.drawCircle(75 + mubiaoX, 75 + mubiaoY, 10, paint1);
canvas.drawCircle(75, 75, 20, paint0);
canvas.drawCircle(75, 75, 70, paint0);
canvas.drawLine(75, 0, 75, 150, paint0);
canvas.drawLine(0, 75, 150, 75, paint0);
iv_canvas.setImageBitmap(baseBitmap);
// 核心代码结束了。=====================================================
}
// 位置设置
public void SetHomeClick(View v) {
LayoutInflater factory = LayoutInflater.from(this);
final View textEntryView = factory.inflate(R.layout.setxml, null);
final EditText editText11 = (EditText) textEntryView.findViewById(R.id.editText11);
final EditText editText12 = (EditText) textEntryView.findViewById(R.id.editText12);
final EditText editText13 = (EditText) textEntryView.findViewById(R.id.editText13);
final EditText editText14 = (EditText) textEntryView.findViewById(R.id.editText14);
final EditText editText15 = (EditText) textEntryView.findViewById(R.id.editText15);
final EditText editText16 = (EditText) textEntryView.findViewById(R.id.editText16);
editText11.setText(String.valueOf(((double)Math.round(yhjd * 18000 / Math.PI)) / 100));
editText12.setText(String.valueOf(((double)Math.round(yhwd * 18000 / Math.PI) )/ 100));
editText13.setText(String.valueOf(Math.round(haiba)));
editText14.setText(String.valueOf(Math.round(cipianjiao)));
editText15.setText(String.valueOf((double) Math.round(xxpl0 * 10000) / 10000));
editText16.setText(String.valueOf((double) Math.round(sxpl0 * 10000) / 10000));
AlertDialog.Builder ad1 = new AlertDialog.Builder(this);
ad1.setTitle("用户设置:");
ad1.setIcon(android.R.drawable.ic_dialog_info);
ad1.setView(textEntryView);
ad1.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int i) {
yhjd = Double.valueOf(editText11.getText().toString()) / 180 * Math.PI;// 用户经度
yhwd = Double.valueOf(editText12.getText().toString()) / 180 * Math.PI;// 用户纬度
haiba = Double.valueOf(editText13.getText().toString());// 海拔
cipianjiao = Double.valueOf(editText14.getText().toString());// 磁偏角
xxpl0 = Double.valueOf(editText15.getText().toString());// 下行频率
sxpl0 = Double.valueOf(editText16.getText().toString());// 上行频率
File f = null;
f = new File("/sdcard/lilacsat.txt");// 这是对应文件名
// f.delete();
try {
String tmp0;
tmp0 = xingli0 + "\n" + xingli1 + "\n" + xingli2 + "\n" + editText11.getText().toString() + "\n"
+ editText12.getText().toString() + "\n" + editText13.getText().toString() + "\n"
+ editText14.getText().toString() + "\n" + editText15.getText().toString() + "\n"
+ editText16.getText().toString() + "\n";
FileOutputStream fout = new FileOutputStream(f);
byte[] bytes = tmp0.getBytes();
fout.write(bytes);
fout.close();
Toast.makeText(MainActivity.this, "已保存用户参数!", 1000).show();
} catch (Exception e) {
e.printStackTrace();
}
}
});
ad1.setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int i) {
}
});
ad1.show();// 显示对话框/
}
// 下载星历
public void DownloadClick(View v) {
// getFile(strURL);
Thread newThread; // 声明一个子线程
newThread = new Thread(new Runnable() {
@Override
public void run() {
// 这里写入子线程需要做的工作
try {
getDataSource(strURL);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Toast.makeText(MainActivity.this, "创建线程", 1000).show();
}
});
newThread.start(); // 启动线程
}
protected void getDataSource(String strPath) throws Exception {
// TODO Auto-generated method stub
// Toast.makeText(MainActivity.this, "下载星历文件核心线程", 2500).show();
// text3.setText("stream null??");
xiaoxi = "正在下载,请稍后……";
URL myURL = new URL(strPath);
URLConnection conn = myURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
if (is == null) {
return;
// text3.setText("stream is null");
}
// text3.setText("stream is NOT null");
File myTempFile = new File("/sdcard/amateur.txt");
FileOutputStream fos = new FileOutputStream(myTempFile);
byte buf[] = new byte[128];
do {
int numread = is.read(buf);
if (numread <= 0) {
break;
}
fos.write(buf, 0, numread);
xiaoxi = "已下载amateur.txt!";
} while (true);
try {
is.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
// 选择卫星******选择卫星******选择卫星******选择卫星******选择卫星******
public void SatelliteClick(View v) {
File f = null;
f = new File("/sdcard/amateur.txt");// 这是对应文件名
if (!(f.exists())) {
Toast.makeText(MainActivity.this, "没有星历文件amateur.txt", 1000).show();
return;
}
InputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream(f));
} catch (FileNotFoundException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
}
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(in, "gb2312"));
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String tmp;
ArrayList<String> list = new ArrayList<String>();
try {
while ((tmp = br.readLine()) != null) {
list.add(tmp);
}
br.close();
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
final String[] xinglit0 = new String[list.size() / 3];
final String[] xinglit1 = new String[list.size() / 3];
final String[] xinglit2 = new String[list.size() / 3];
for (int j = 0; j < (list.size() / 3); j++) {
xinglit0[j] = list.get(j * 3);
xinglit1[j] = list.get(j * 3 + 1);
xinglit2[j] = list.get(j * 3 + 2);
}
new AlertDialog.Builder(this).setTitle("请选择卫星").setIcon(android.R.drawable.ic_dialog_info)
.setSingleChoiceItems(xinglit0, 0, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
xingli0 = xinglit0[which];
xingli1 = xinglit1[which];
xingli2 = xinglit2[which];
xlsat = xingli0;
timep = xingli1.substring(18, 32);
qingjiao = Double.valueOf(xingli2.substring(8, 16)) / 180 * Math.PI;// 轨道倾角
chijing = Double.valueOf(xingli2.substring(17, 25)) / 180 * Math.PI;// 升交点赤经
pianxinlv = Double.valueOf("0." + xingli2.substring(26, 33));// 轨道偏心率
jddfj = Double.valueOf(xingli2.substring(34, 42)) / 180 * Math.PI;// 近地点幅角
pjdj = Double.valueOf(xingli2.substring(43, 51)) / 180 * Math.PI;// 平近点角
mrrxqs = Double.valueOf(xingli2.substring(52, 63));// 每日绕行圈数
xiaoxi = ("已载入星历:" + xlsat + "\n星历时间:" + timep + "\n轨道倾角:" + qingjiao * 180 / Math.PI
+ "\n升交点赤经:" + chijing * 180 / Math.PI + "\n轨道偏心率:" + pianxinlv + "\n近地点幅角:"
+ jddfj * 180 / Math.PI + "\n平近点角:" + pjdj * 180 / Math.PI + "\n每日绕行圈数:" + mrrxqs);
Toast.makeText(MainActivity.this, "你选择了: " + xingli0, 1000).show();
File f = null;
f = new File("/sdcard/lilacsat.txt");// 这是对应文件名
try {// 写入配置文件
String tmp0;
tmp0 = xingli0 + "\n" + xingli1 + "\n" + xingli2 + "\n"
+ String.valueOf(((double)Math.round(yhjd * 18000 / Math.PI)) / 100) + "\n"
+ String.valueOf(((double)Math.round(yhwd * 18000 / Math.PI)) / 100) + "\n"
+ String.valueOf(Math.round(haiba)) + "\n" + String.valueOf(Math.round(cipianjiao))
+ "\n" + String.valueOf((double) Math.round(xxpl0 * 10000) / 10000) + "\n"
+ String.valueOf((double) Math.round(sxpl0 * 10000) / 10000) + "\n";
FileOutputStream fout = new FileOutputStream(f);
byte[] bytes = tmp0.getBytes();
fout.write(bytes);
fout.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}).setNegativeButton("取消", null).show();
}
// 结束程序
public void FinishClick(View v) {
finish();
}
// 程序初始化时,读取记录文件,没有lilacsat文件就创建一个。
public void Update() {
// String urlStr="http://lilacsat.hit.edu.cn/tle/lilacsat.txt";
File f = null;
f = new File("/sdcard/lilacsat.txt");// 这是对应文件名
if (!(f.exists())) {
try {// 写入配置文件
String tmp0;
tmp0 = xingli0 + "\n" + xingli1 + "\n" + xingli2 + "\n"
+ String.valueOf(((double)Math.round(yhjd * 18000 / Math.PI)) / 100) + "\n"
+ String.valueOf(((double)Math.round(yhwd * 18000 / Math.PI)) / 100) + "\n"
+ String.valueOf(Math.round(haiba)) + "\n" + String.valueOf(Math.round(cipianjiao)) + "\n"
+ String.valueOf((double) Math.round(xxpl0 * 10000) / 10000) + "\n"
+ String.valueOf((double) Math.round(sxpl0 * 10000) / 10000) + "\n";
FileOutputStream fout = new FileOutputStream(f);
byte[] bytes = tmp0.getBytes();
fout.write(bytes);
fout.close();
} catch (Exception e) {
e.printStackTrace();
}
Toast.makeText(MainActivity.this, "首次运行并创建配置文件!", 1000).show();
}
InputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream(f));
} catch (FileNotFoundException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
}
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(in, "gb2312"));
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String tmp;
try {
// while((tmp=br.readLine())!=null){
tmp = br.readLine();
xingli0 = tmp;
xlsat = tmp;
// 在这对tmp操作
tmp = br.readLine();
xingli1 = tmp;
timep = tmp.substring(18, 32);
tmp = br.readLine();
xingli2 = tmp;
qingjiao = Double.valueOf(tmp.substring(8, 16)) / 180 * Math.PI;// 轨道倾角
chijing = Double.valueOf(tmp.substring(17, 25)) / 180 * Math.PI;// 升交点赤经
pianxinlv = Double.valueOf("0." + tmp.substring(26, 33));// 轨道偏心率
jddfj = Double.valueOf(tmp.substring(34, 42)) / 180 * Math.PI;// 近地点幅角
pjdj = Double.valueOf(tmp.substring(43, 51)) / 180 * Math.PI;// 平近点角
mrrxqs = Double.valueOf(tmp.substring(52, 63));// 每日绕行圈数
tmp = br.readLine();
yhjd = Double.valueOf(tmp) / 180 * Math.PI;// 用户经度
tmp = br.readLine();
yhwd = Double.valueOf(tmp) / 180 * Math.PI;// 用户纬度
tmp = br.readLine();
haiba = Double.valueOf(tmp);// 海拔
tmp = br.readLine();
cipianjiao = Double.valueOf(tmp);// 磁偏角
tmp = br.readLine();
xxpl0 = Double.valueOf(tmp);// 下行频率
tmp = br.readLine();
sxpl0 = Double.valueOf(tmp);// 上行频率
br.close();
in.close();
xiaoxi = ("已载入星历:" + xlsat + "\n星历时间:" + timep + "\n轨道倾角:" + qingjiao * 180 / Math.PI + "\n升交点赤经:"
+ chijing * 180 / Math.PI + "\n轨道偏心率:" + pianxinlv + "\n近地点幅角:" + jddfj * 180 / Math.PI + "\n平近点角:"
+ pjdj * 180 / Math.PI + "\n每日绕行圈数:" + mrrxqs);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}