Skip to content

Commit

Permalink
Coordinates ok
Browse files Browse the repository at this point in the history
  • Loading branch information
farom57 committed May 23, 2015
1 parent 30a0140 commit 40f46d4
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 9 deletions.
53 changes: 52 additions & 1 deletion app/src/main/java/farom/iparcos/catalog/Coordinates.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public class Coordinates {
* @param de_str
*/
public Coordinates(String ra_str, String de_str){
// TODO
ra = convertRa(ra_str);
de = convertDe(de_str);
}

/**
Expand Down Expand Up @@ -119,6 +120,51 @@ static public double convertDe(String str) throws NumberFormatException{
}
}

/**
* Right ascension in deg
* @return
*/
public double getRa() {
return ra;
}

/**
* Declination in deg
* @return
*/
public double getDe() {
return de;
}

/**
* Return a string with the right ascension (hh:mm:ss)
* @return
*/
public String getRaStr(){
int deg = (int)Math.floor(Math.abs(ra)/15);
int min = (int)Math.floor((Math.abs(ra)/15-deg)*60);
int sec = (int)Math.round(((Math.abs(ra)/15-deg)*60-min)*60);
return String.format("%02d:%02d:%02d",deg,min,sec);
}

/**
* Return a string with the right ascension (hh:mm:ss)
* @return
*/
public String getDeStr(){
int deg = (int)Math.floor(Math.abs(de));
int min = (int)Math.floor((Math.abs(de)-deg)*60);
int sec = (int)Math.round(((Math.abs(de)-deg)*60-min)*60);
if(Math.signum(de)>=0) {
return String.format("+%02d:%02d:%02d", deg, min, sec);
}else{
return String.format("-%02d:%02d:%02d", deg, min, sec);
}
}

public String toString(){
return "RA: "+getRaStr()+" DE: " + getDeStr();
}

// static void test(){
// Log.d("Coordinates_Test"," --- RA --- ");
Expand Down Expand Up @@ -178,6 +224,11 @@ static public double convertDe(String str) throws NumberFormatException{
// }catch(NumberFormatException e) {
// Log.d("Coordinates_Test",e.getMessage());
// }
//
// Log.d("Coordinates_Test",(new Coordinates("12:34:56.789","-12:34:56.789")).toString());
// Log.d("Coordinates_Test",(new Coordinates("1h02m10s","+1:2:3.04")).toString());
//
//
// }

}
17 changes: 9 additions & 8 deletions app/src/main/java/farom/iparcos/catalog/StarEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public class StarEntry extends CatalogEntry {
protected String name;
protected String names;
protected String magnitude;
protected String ra;
protected String de;
protected Coordinates coord;

/**
* Create the entry from a formated line
Expand All @@ -49,12 +48,14 @@ public StarEntry(char[] buf) {
names = data.substring(i, i + namesLength).trim();
i += namesLength;

ra = data.substring(i, i + raLength).trim();
String ra_str = data.substring(i, i + raLength).trim();
i += raLength+1;

de = data.substring(i, i + deLength).trim();
String de_str = data.substring(i, i + deLength).trim();
i += deLength+1;

coord = new Coordinates(ra_str,de_str);

magnitude = data.substring(i, i + magnitudeLength).trim();
i += magnitudeLength;
}
Expand All @@ -66,7 +67,7 @@ public StarEntry(char[] buf) {
*/
@Override
public Coordinates getCoordinates() {
return null;
return coord;
}

/**
Expand All @@ -91,9 +92,9 @@ public Spannable createDescription(Context ctx) {
String str = "<b>" + r.getString(R.string.entry_names) + r.getString(R.string.colon_with_spaces) + "</b>" + names + "<br/>";
str += "<b>" + r.getString(R.string.entry_type) + r.getString(R.string.colon_with_spaces) + "</b>" + r.getString(R.string.entry_star) + "<br/>";
str += "<b>" + r.getString(R.string.entry_magnitude) + r.getString(R.string.colon_with_spaces) + "</b>" + magnitude + "<br/>";
str += "<b>" + r.getString(R.string.entry_RA) + r.getString(R.string.colon_with_spaces) + "</b>" + ra + "<br/>";
str += "<b>" + r.getString(R.string.entry_DE) + r.getString(R.string.colon_with_spaces) + "</b>" + de;
Coordinates.test();
str += "<b>" + r.getString(R.string.entry_RA) + r.getString(R.string.colon_with_spaces) + "</b>" + coord.getRaStr() + "<br/>";
str += "<b>" + r.getString(R.string.entry_DE) + r.getString(R.string.colon_with_spaces) + "</b>" + coord.getDeStr();

return new SpannableString(Html.fromHtml(str));
}

Expand Down

0 comments on commit 40f46d4

Please sign in to comment.