- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我的第一个 Activity ,每当我尝试使用 Intent 传递 double “纬度和经度”时,我的应用程序崩溃,我不知道还能做什么。
我看到如果我不放 startActivity(Intent) ii 就不会崩溃。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//
requestPermission();
//
client = LocationServices.getFusedLocationProviderClient(this);
Button button = findViewById(R.id.getLocation);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(ActivityCompat.checkSelfPermission(MainActivity.this, ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED){
return;
}
client.getLastLocation().addOnSuccessListener(MainActivity.this, new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
if (location != null) {
TextView textView = findViewById(R.id.location);
textView.setText(location.toString());
}
double latitude = location.getLatitude();
double longitude = location.getLongitude();
Intent intent = new Intent(getApplicationContext(), MapsActivity.class);
intent.putExtra("Lat",latitude);
intent.putExtra("Lon",longitude);
startActivity(intent);
}
});
}
});
public class MapsActivity extends AppCompatActivity implements OnMapReadyCallback {
private GoogleMap mMap;
public static final String FILENAME = "filename";
private ArrayList<Entity> selectedSat;
String fileName;
MenuItem favItem;
private DecimalFormat df = new DecimalFormat("#.00");
private Frame earthFixedFrame;
private OneAxisEllipsoid earth;
protected GeodeticPoint pointPlot = null;
protected Marker currentMarker = null;
protected Polyline line = null;
protected Polyline pastLine = null;
public static final int PATTERN_DASH_LENGTH_PX = 20;
public static final int PATTERN_GAP_LENGTH_PX = 20;
public static final PatternItem DOT = new Dot();
public static final PatternItem DASH = new Dash(PATTERN_DASH_LENGTH_PX);
public static final PatternItem GAP = new Gap(PATTERN_GAP_LENGTH_PX);
public static final List<PatternItem> PATTERN_POLYGON_ALPHA = Arrays.asList(GAP, DASH);
protected ArrayList<Marker> markers = new ArrayList<>();
boolean initial = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_ACTION_BAR);
Drawable fav = getDrawable(R.drawable.favoritesicon);
fav.setColorFilter(Color.parseColor("#FFFFFF"), PorterDuff.Mode.MULTIPLY);
selectedSat = SatelliteSelectActivity.getSelectedSat(); //Pulls a list of selected satellites from the previous activity
System.out.println(selectedSat.get(0).getName());
setContentView(R.layout.activity_maps);
ActionBar ab = getSupportActionBar();
if (ab != null) {
ab.setTitle(selectedSat.get(0).getName().trim());
}
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
fileName = getIntent().getStringExtra(FILENAME);
int i = 0;
System.out.println(selectedSat.get(i).getName()); //Prints Entity Name to the Console
try {
System.out.println("Velocidad:");
System.out.println(selectedSat.get(i).getVelocity()); //Prints the velocity of the entity
} catch (OrekitException e) {
e.printStackTrace();
}
}
public void onBackPressed() { //Runs when you exit the activity
selectedSat.clear(); //Clears the satellite list
System.out.println("Terminar con el mapa"); //Prints to the console that we are done with the Maps activity
initial = false; //Boolean variable specifying we are dealing with the first satellite
Intent intent = new Intent(getApplicationContext(), SatelliteSelectActivity.class);
startActivity(intent);
this.finish(); //Closes the activity
}
@Override
public boolean onCreateOptionsMenu(Menu menu) { //Creates action bar in the MapsActivity UI
MenuInflater item = getMenuInflater(); //Specifies the item fit
item.inflate(R.menu.actionbar, menu); //Fits the menu to the item fit
setTitle("SatFun"); //Sets the action bar title
favItem = menu.findItem(R.id.actionbar_fav);
checkifFavorite(); // see if sat is favorite
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) { //Called when icon in the action bar is selected
switch (item.getItemId()) {
case R.id.actionbar_fav:
selectedSat = SatelliteSelectActivity.getSelectedSat();
String fileName = getIntent().getStringExtra(FILENAME);
if (!Favorites.contains(selectedSat.get(0).getName(), fileName, getApplicationContext())) {
item.setIcon(R.drawable.favoritesicon_filled);
for (int i = 0; i < selectedSat.size(); i++)
try {
Favorites.addFavorite(selectedSat.get(i).getName(), selectedSat.get(i).getLine1(), selectedSat.get(i).getLine2(), fileName, getApplicationContext());
return true;
} catch (OrekitException e) {
e.printStackTrace();
}
} else {
item.setIcon(R.drawable.favoritesicon);
for (int i = 0; i < selectedSat.size(); i++) {
try {
boolean removed = Favorites.removeFavorite(selectedSat.get(i).getName(), selectedSat.get(i).getLine1(), selectedSat.get(i).getLine2(), fileName, getApplicationContext());
System.out.print(removed);
} catch (OrekitException e) {
e.printStackTrace();
}
}
return true;
}
case R.id.actionbar_info:
ConstraintLayout satInfo = findViewById(R.id.satelliteInfo);
if (satInfo.getVisibility() == View.INVISIBLE) {
satInfo.setVisibility(View.VISIBLE);
} else {
satInfo.setVisibility(View.INVISIBLE);
}
}
return super.onOptionsItemSelected(item);
}
@Override
public void onMapReady(final GoogleMap googleMap) {
mMap = googleMap;
mapUpdater(getCreatedTime());
}
private int incr = 0;
public void mapUpdater(Date date) {
if (date == null) {
dateTime = getCreatedTime();
} else {
dateTime = date;
}
new Thread() {
public void run() {
System.out.println("Nueva");
while (incr++ < 1000) {
try {
runOnUiThread(new Runnable() {
@Override
public void run() {
try {
updateMap();
} catch (OrekitException e) {
e.printStackTrace();
}
}
});
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}.start();
}
private void setPastLine(AbsoluteDate date, double satPeriod) {
ArrayList<LatLng> plotPoints = new ArrayList<>();
for (int k = 0; k < 50; k++) {
int period = (int) Math.round(satPeriod);
int periodMin = (period / 100);
System.out.println("DATE: " + date);
pointPlot = updatePosition(date, 0);
System.out.println("FRAGMENT (width, height): " + findViewById(R.id.map).getWidth() + " " + findViewById(R.id.map).getHeight());
double longitude = pointPlot.getLongitude() * 180 / Math.PI;
double latitude = pointPlot.getLatitude() * 180 / Math.PI;
//Creates map objects
LatLng point_a = new LatLng(latitude, longitude);
MarkerOptions point = new MarkerOptions().position(point_a);
plotPoints.add(point_a);
date = new AbsoluteDate(date, -periodMin);
}
pastLine = mMap.addPolyline(new PolylineOptions().addAll(plotPoints));
pastLine.setWidth(5);//Sets width of polyline
pastLine.setPattern(PATTERN_POLYGON_ALPHA);
pastLine.setColor(Color.RED);
}
private Date getCreatedTime() { //Creates a new date with the current time and returns it
return new Date();
}
private Date dateTime = null;
private void updateMap() throws OrekitException {
System.out.println("Entering update map");
if (dateTime == null) {
dateTime = getCreatedTime();
}
AbsoluteDate date;
for (int i = 0; i < selectedSat.size(); i++) {
double satNum = selectedSat.get(i).getSatNum();
TextView satNumberText = findViewById(R.id.satelliteNumber);
String satelliteNumberString = "Número De Satelite: " + Math.round(satNum);
satNumberText.setText(satelliteNumberString);
TimeScale utc = TimeScalesFactory.getUTC();
ArrayList<LatLng> plotPoints = new ArrayList<>();
Calendar calendar = GregorianCalendar.getInstance();
double satPeriod = selectedSat.get(i).getPeriod();
int period = (int) Math.round(satPeriod);
int periodMin = (period / 100);
System.out.println("Interval: " + periodMin);
calendar.setTime(dateTime);
System.out.println(calendar.get(Calendar.YEAR));
calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
date = new AbsoluteDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND), utc); //creates orekit absolute date from calender
this.initializeFrames();
pointPlot = updatePosition(date, 0);
String velocityString = df.format(selectedSat.get(i).getVelocity() * 3.6);
velocityString = "Velocidad: " + velocityString + "km/h";
TextView satVelocity = findViewById(R.id.velocity);
satVelocity.setText(velocityString);
//Finds longitude
double longitude = pointPlot.getLongitude() * 180 / Math.PI;
String longitudeString = "Longitud: " + df.format(longitude);
TextView satLongitude = findViewById(R.id.satLongitude);
satLongitude.setText(longitudeString);
//Finds latitude
double latitude = pointPlot.getLatitude() * 180 / Math.PI;
String latitudeString = "Latitud: " + df.format(latitude);
TextView satLatitude = findViewById(R.id.satLatitude);
satLatitude.setText(latitudeString);
double altitude = pointPlot.getAltitude() / 1000;
TextView satAltitude = findViewById(R.id.satAltitude);
String altitudeString = "Altitud: " + df.format(altitude) + "km";
satAltitude.setText(altitudeString);
//CALCULOS
double longi= 78.5082717;
double lati=0.245496;
double delta1 = Math.abs(longitude);
double delta = Math.abs(delta1-longi);
double elev=Math.atan(((Math.cos(lati)*Math.cos(delta))-(6378/42164))/Math.sin(Math.acos(Math.cos(lati)*Math.cos(delta))));
double az1 = Math.tan(Math.toDegrees(delta));
double az2 = Math.sin(Math.toDegrees(lati));
double az3 = Math.toDegrees(az1/az2);
double az = Math.abs(Math.toDegrees(Math.atan(az3)));
double dis1 = (Math.cos(Math.toRadians(lati)));
double dis2 = (Math.cos(Math.toRadians(delta)));
double dis3 = (dis1*dis2);
double dis4 = (1-dis3);
double dis5 = (0.41999*dis4);
double dis6 = (1+dis5);
double dis = (35786.04*(Math.sqrt(dis6)));
TextView satdelta = findViewById(R.id.satdelta);
String deltaString = "Delta: " + df.format(delta);
satdelta.setText(deltaString);
TextView azimuts = findViewById(R.id.azimut);
String AzimutString = "Azimut: " + df.format(az);
azimuts.setText(AzimutString);
TextView disf = findViewById(R.id.distancia);
String disString = "Distancia: " + df.format(dis) + "Km";
disf.setText(disString);
//////////////////////////////////////////////////////////
System.out.println("Latitud: " + latitude);
System.out.println("Longitud: " + longitude);
System.out.println("PERIODO: " + periodMin);
for (int k = 0; k < 300; k++) {
System.out.println("DATE: " + date);
pointPlot = updatePosition(date, i);
System.out.println("FRAGMENT (width, height): " + findViewById(R.id.map).getWidth() + " " + findViewById(R.id.map).getHeight());
longitude = pointPlot.getLongitude() * 180 / Math.PI;
latitude = pointPlot.getLatitude() * 180 / Math.PI;
//Creates map objects
LatLng point_a = new LatLng(latitude, longitude);
MarkerOptions pointA = new MarkerOptions().position(point_a);
if (k == 0) {
if(currentMarker != null) {
currentMarker.remove();
}
if(line != null) {
line.remove();
}
if(pastLine != null) {
pastLine.remove();
}
}
pointA.title(selectedSat.get(i).getName().trim() + "Poscicion Actual");
if (initial) {
initial = false;
mMap.moveCamera(CameraUpdateFactory.newLatLng(point_a));
}
}
plotPoints.add(point_a);
date = new AbsoluteDate(date, periodMin);
}
date = new AbsoluteDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND), utc); //creates orekit absolute date from calender
setPastLine(date, satPeriod);
line = mMap.addPolyline(new PolylineOptions().addAll(plotPoints));
line.setWidth(5);
line.setColor(Color.RED);
}
}
private void initializeFrames() {
try {
Frame f;
f = CelestialBodyFactory.getEarth().getBodyOrientedFrame();
earthFixedFrame = FramesFactory.getTEME();
earth = new OneAxisEllipsoid(
Constants.WGS84_EARTH_EQUATORIAL_RADIUS,
Constants.WGS84_EARTH_FLATTENING,
f);
} catch (OrekitException e) {
System.out.println("ERROR");
e.printStackTrace();
}
}
private GeodeticPoint updatePosition(AbsoluteDate date, int i) {
GeodeticPoint point = null;
SpacecraftState scs = selectedSat.get(i).updateState(date);
System.out.println(scs);
System.out.println(scs.getPVCoordinates().getPosition());
System.out.println(scs.getDate());
System.out.println(earthFixedFrame);
try {
point = earth.transform(selectedSat.get(i).getVector(date), earthFixedFrame, date);
} catch (OrekitException e) {
System.out.println("Fallo al realizar la conversion cartesiana");
e.printStackTrace();
}
return point;
}
private void checkifFavorite() {
if (fileName.contains("favorites_")) {
fileName = fileName.replace("favorites_", "");
}
File test1 = new File(this.getFilesDir(), "favorites_" + fileName);
if (test1.exists()) {
System.out.println("file exists");
try {
ArrayList<String> favs = celestrakData.getNames("favorites_" + fileName, this);
if (favs.contains(selectedSat.get(0).getName())) {
System.out.println("already is a favorite");
favItem.setIcon(R.drawable.favoritesicon_filled);
}
} catch (IOException e) {
e.printStackTrace();
}
} else {
System.out.println("file doesnt exist");
}
}
最佳答案
您可以尝试传递您所在的 Activity 的上下文,而不是按照您的 Intent 使用 getApplicationContext()。
Intent intent = new Intent(yourActivityName.this, MapsActivity.class);
关于java - 不能使用 Intent 将数据移动到另一个 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61549764/
只是想知道 Jquery Mobile 是否足够稳定以用于实时生产企业移动应用程序。 有很多 HTML5 框架,因为我们的团队使用 JQuery 已经有一段时间了,我们更愿意使用 Jquery 移动框
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 3 年前。 Improve t
所以我尝试在 JavaScript 中对元素进行拖放。我使用的视频教程在这里; https://www.youtube.com/watch?v=KTlZ4Hs5h80 。我已经按照它的说明进行了编码,
无法在移动 iOS(safari 和 chrome)上自动播放以前缓存的 mp3 音频 我正在 Angular 8 中开发一个应用程序,在该应用程序的一部分中,我试图在对象数组中缓存几个传入的音频 m
Git 基于内容而不是文件,所以我目前理解以下行为,但我想知道是否有特殊选项或 hack 来检测此类事情: git init mkdir -p foo/bar echo "test" foo/a.tx
我正在寻找语义 ui 正确的类来隐藏例如移动 View 中的 DIV。在 Bootstrap 中,我们有“visible-xs”和“hidden-xs”。 但是在语义ui上我只找到了“仅移动网格” 最
我正在使用 ubuntu 和 想要移动或复制大文件。 但是当我与其他人一起使用服务器时,我不想拥有所有内存并使其他进程几乎停止。 那么有没有办法在内存使用受限的情况下移动或复制文件? 最佳答案 如果你
这些指令有什么区别?以 ARM9 处理器为例,它不应该是: ASM: mov r0, 0 C: r0 = 0; ASM: ld r0, 0 C: r0 = 0; ? 我不知道为什么要使用一个或另一个:
我有一个文件夹,其中包含一些随机命名的文件,其中包含我需要的数据。 为了使用数据,我必须将文件移动到另一个文件夹并将文件命名为“file1.xml” 每次移动和重命名文件时,它都会替换目标文件夹中以前
我经常在 IB/Storyboard 中堆叠对象,几乎不可能拖动其他对象后面的对象而不移动前面的对象。无论如何我可以移动已经选择但位于其他对象后面的对象吗?当我尝试移动它时,它总是选择顶部的对象,还是
几个月前,我看到 Safari 7 允许推送通知,它似乎是一个非常有用的工具,除了我看到的每个示例都专注于桌面浏览,而不是移动设备。 Safari 推送通知是否可以在移动设备上运行,如果没有,是否有计
我有一个简单的 View 模型,其中包含修改后的 ObservableCollection使用 SynchronizationContext.Current.Send在 UI 线程上执行对集合的更改。
关于cassandra创建的数据文件和系统文件的位置,我需要移动在“cassandra.yaml”配置文件中设置的“commitlog_directory”、“data_file_directorie
我有这个代码 $(function() { var message = 'Dont forget us'; var original; var txt1 = ' - '; $(wind
我的客户报告说他的网站有一个奇怪的问题。该网站的 URL 是 your-montenegro.me 在 基于 Android 的浏览器 上加载时,页面底部会出现一个奇怪的空白区域。以下是屏幕截图: 华
我有这个 HTML 标记: Express 300 bsf Sign Up 我需要将元素从 DOM 上的一个
我有一个可重新排序的 TableView (UITableView 实例)。尽管我已经实现了 UITableViewDataSource 方法: tableView:moveRowAtIndexPat
我的客户报告说他的网站有一个奇怪的问题。该网站的 URL 是 your-montenegro.me 在 基于 Android 的浏览器 上加载时,页面底部会出现一个奇怪的空白区域。以下是屏幕截图: 华
我需要在拖放或复制/剪切和粘贴(复制与移动)期间获取操作类型。它是一个 Swing 应用程序,并且实现了 TransferHandle。我在操作结束时需要此信息,在 importData 方法中。 对
我编写了一个具有 add 和 get 方法的 SortedIntList 类。 我调用以下四个方法: SortedIntList mySortedIntList = new SortedIntList
我是一名优秀的程序员,十分优秀!