|
From: Adam B. <ab...@us...> - 2005-04-08 17:36:10
|
Update of /cvsroot/hipgmap/gmap/com/trileet/gmap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16048 Modified Files: GMap.java ImageCache.java MapWindow.java Point.java Tile.java TileSet.java Log Message: A nearly functional photo routine. Pressing Menu+Q takes you into Photo mode, where your photo will be displayed instead of the map. The photo is also requested when you go into photo mode. It is NOT requested if you scroll off the photo--you have to go back to map mode (menu+q) and into photo mode again to make the request. This is to limit bandwidth-heavy requests of photos. Right now, it's set to use Nic's img.php script to convert the JPEGs to PNGs. However, the phone doesn't seem to be able to decode _those_ either. Index: Point.java =================================================================== RCS file: /cvsroot/hipgmap/gmap/com/trileet/gmap/Point.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Point.java 8 Apr 2005 00:07:53 -0000 1.5 --- Point.java 8 Apr 2005 17:35:58 -0000 1.6 *************** *** 89,106 **** private static final hipfloat h180 = new hipfloat(180); private static final hipfloat h360 = new hipfloat(360); ! private static final hipfloat h2p18 = new hipfloat(1<<19); private static final char[] KHCHARS = {'t','q','s','r'}; /** ! * Returns a string of length 19. First char is t. Remaining * chars encode the given point. */ public static String latLngToKH(hipfloat lat, hipfloat lng) { ! int y = lat.add(h180).div(h360).mul(h2p18).toint(); ! int x = lng.add(h180).div(h360).mul(h2p18).toint(); ! char[] outArr = new char[19]; ! for (int i=0; i<19; i++) { ! int index = ((x & 1<<(19-i))>>(18-i)); ! index |= ((y & 1<<(19-i))>>(19-i)); outArr[i] = KHCHARS[index]; } --- 89,106 ---- private static final hipfloat h180 = new hipfloat(180); private static final hipfloat h360 = new hipfloat(360); ! private static final hipfloat h2p26 = new hipfloat(1<<27); private static final char[] KHCHARS = {'t','q','s','r'}; /** ! * Returns a string of length 27. First char is t. Remaining * chars encode the given point. */ public static String latLngToKH(hipfloat lat, hipfloat lng) { ! int y = lat.add(h180).div(h360).mul(h2p26).toint(); ! int x = lng.add(h180).div(h360).mul(h2p26).toint(); ! char[] outArr = new char[27]; ! for (int i=0; i<27; i++) { ! int index = ((x & 1<<(27-i))>>(26-i)); ! index |= ((y & 1<<(27-i))>>(27-i)); outArr[i] = KHCHARS[index]; } Index: ImageCache.java =================================================================== RCS file: /cvsroot/hipgmap/gmap/com/trileet/gmap/ImageCache.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** ImageCache.java 8 Apr 2005 00:07:52 -0000 1.10 --- ImageCache.java 8 Apr 2005 17:35:58 -0000 1.11 *************** *** 125,130 **** System.out.println("Got a kh response"); kh = true; - /** System.out.println(bytes.length); for (int i=0; i<=32; i++) { System.out.print(Integer.toHexString((int)(bytes[i]))); --- 125,130 ---- System.out.println("Got a kh response"); kh = true; System.out.println(bytes.length); + /** for (int i=0; i<=32; i++) { System.out.print(Integer.toHexString((int)(bytes[i]))); Index: TileSet.java =================================================================== RCS file: /cvsroot/hipgmap/gmap/com/trileet/gmap/TileSet.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** TileSet.java 8 Apr 2005 00:07:53 -0000 1.22 --- TileSet.java 8 Apr 2005 17:35:58 -0000 1.23 *************** *** 248,253 **** m_offsetX = m_offsetX % TILE_WIDTH + TILE_WIDTH * 2; m_offsetY = m_offsetY % TILE_WIDTH + TILE_WIDTH * 2; ! photoAvailable = ImageCache.hasImage(Tile.makePhotoURL(Point.latLngToKH(getLat(),getLng()),m_zoom)); } } --- 248,263 ---- m_offsetX = m_offsetX % TILE_WIDTH + TILE_WIDTH * 2; m_offsetY = m_offsetY % TILE_WIDTH + TILE_WIDTH * 2; ! } + /** + String khCenter = Point.latLngToKH(getLat(),getLng()); + String khTail = khCenter.substring(18-m_zoom); + + System.out.println(khCenter); + System.out.println(khToXOff(khTail)); + System.out.println(khToYOff(khTail)); + **/ + if (displayPhoto) + enterPhotoMode(); } *************** *** 354,411 **** // paints this tile set, given the offset from the center ! public void paint(Pen p) { ! if (!displayPhoto) { ! int m_hitX = -1; ! int m_hitY = -1; ! for (int x = 0; x < getWidth(); x++) { ! for (int y = 0; y < getHeight(); y++) { ! int startX = x * TILE_WIDTH - m_offsetX; ! int startY = y * TILE_WIDTH - m_offsetY; ! if (startX > -TILE_WIDTH && startX < 240 ! && startY > -TILE_WIDTH && startY < 140) { ! m_tiles[x][y].paint(p, startX, startY); ! } ! } } ! // draw our hits ! int startX = m_tiles[0][0].getX(); ! int startY = m_tiles[0][0].getY(); ! // draw our polyline. ! if (m_polyline != null && m_drawPoly) { ! m_polyline.paint(p, m_offsetX, m_offsetY, startX, startY, m_zoom); ! } ! ! for (int i = 0; i < GMap.s_hits.size(); i++) { ! Hit hit = (Hit) GMap.s_hits.elementAt(i); ! // if this is our current hit, skip it, we'll draw it last ! if (i != m_currentHit){ ! hit.paint(p, m_offsetX, m_offsetY, startX, startY, m_zoom, false); ! } ! } ! // draw our current hit ! if (m_currentHit >= 0 && m_currentHit < GMap.s_hits.size()){ ! Hit hit = (Hit) GMap.s_hits.elementAt(m_currentHit); ! hit.paint(p, m_offsetX, m_offsetY, startX, startY, m_zoom, (m_display == DISPLAY_ALL)); ! } ! } ! else { ! // Photo mode. ! String khCenter = Point.latLngToKH(getLat(),getLng()); ! Bitmap photo = ImageCache.requestImage(Tile.makePhotoURL(khCenter,m_zoom),null); ! if (photo == null) { ! System.out.println("Null photo!"); ! return; ! } ! String khTail = khCenter.substring(18-m_zoom); ! p.drawBitmap(khToXOff(khTail),khToYOff(khTail),photo); ! } } public int getHeight() { --- 364,421 ---- // paints this tile set, given the offset from the center ! public void paint(Pen p) { ! int m_hitX = -1; ! int m_hitY = -1; ! if (!displayPhoto) { ! for (int x = 0; x < getWidth(); x++) { ! for (int y = 0; y < getHeight(); y++) { ! int startX = x * TILE_WIDTH - m_offsetX; ! int startY = y * TILE_WIDTH - m_offsetY; ! if (startX > -TILE_WIDTH && startX < 240 ! && startY > -TILE_WIDTH && startY < 140) { ! m_tiles[x][y].paint(p, startX, startY); ! } } + } + } + else { + // Photo mode. + p.drawRect(m_offsetXPhoto,m_offsetYPhoto, + m_offsetXPhoto+256,m_offsetYPhoto+256); + if (m_photo != null) { + p.drawBitmap(m_offsetXPhoto,m_offsetYPhoto,m_photo); + } + else { + p.drawText(m_offsetXPhoto+128,m_offsetYPhoto+128,"Wait"); + } ! } ! // draw our hits ! int startX = m_tiles[0][0].getX(); ! int startY = m_tiles[0][0].getY(); ! ! // draw our polyline. ! if (m_polyline != null && m_drawPoly) { ! m_polyline.paint(p, m_offsetX, m_offsetY, startX, startY, m_zoom); ! } ! for (int i = 0; i < GMap.s_hits.size(); i++) { ! Hit hit = (Hit) GMap.s_hits.elementAt(i); ! // if this is our current hit, skip it, we'll draw it last ! if (i != m_currentHit){ ! hit.paint(p, m_offsetX, m_offsetY, startX, startY, m_zoom, false); } } + + // draw our current hit + if (m_currentHit >= 0 && m_currentHit < GMap.s_hits.size()){ + Hit hit = (Hit) GMap.s_hits.elementAt(m_currentHit); + hit.paint(p, m_offsetX, m_offsetY, startX, startY, m_zoom, (m_display == DISPLAY_ALL)); + } + } public int getHeight() { *************** *** 504,509 **** } } ! ! public void drill(int x, int y, int zoom, int lowestZoom) { /** * Assume the given map tile is of interest. We will --- 514,527 ---- } } ! public void drill() { ! /** ! * Drill the center tile and current zoom, down to 2. ! */ ! drill(m_tiles[getWidth()/2][getHeight()/2].getX(), ! m_tiles[getWidth()/2][getHeight()/2].getY(), ! m_zoom, ! 2); ! } ! private void drill(int x, int y, int zoom, int lowestZoom) { /** * Assume the given map tile is of interest. We will *************** *** 521,525 **** public void enterPhotoMode() { ! System.out.println("Photo mode on"); displayPhoto = true; GMap.invalidateMap(); --- 539,558 ---- public void enterPhotoMode() { ! // Mess with photo ! String khCenter = Point.latLngToKH(getLat(),getLng()); ! String photoURL = Tile.makePhotoURL(khCenter,m_zoom); ! if (ImageCache.hasImage(photoURL)) { ! m_photo = ImageCache.requestImage(photoURL,null); ! } ! else { ! m_photo = null; ! } ! String khTail = khCenter.substring(18-m_zoom); ! /** ! **/ ! m_offsetXPhoto = khToXOff(khTail); ! m_offsetYPhoto = khToYOff(khTail); ! ! displayPhoto = true; GMap.invalidateMap(); *************** *** 599,606 **** 2); **/ ! String tempurl = Tile.makePhotoURL(Point.latLngToKH(getLat(),getLng()),m_zoom); ! photoAvailable = ImageCache.hasImage(tempurl); System.out.println("Photo "+(photoAvailable?"yes":"no")); ! if (photoAvailable && !displayPhoto) { enterPhotoMode(); } --- 632,647 ---- 2); **/ ! boolean photoAvailable = (m_photo != null); System.out.println("Photo "+(photoAvailable?"yes":"no")); ! if (!photoAvailable) { ! String khCenter = Point.latLngToKH(getLat(),getLng()); ! String photoURL = Tile.makePhotoURL(khCenter,m_zoom); ! ! ImageCache.requestImage(photoURL, ! null, true); ! } ! if (!displayPhoto) { ! System.out.println("Photo mode on"); ! enterPhotoMode(); } *************** *** 608,615 **** exitPhotoMode(); } - else { - ImageCache.requestImage(tempurl, - null, true); - } m_debug = !m_debug; --- 649,652 ---- *************** *** 698,703 **** public MapWindow parentMapWindow; - public boolean photoAvailable = false; private boolean displayPhoto = false; int m_offsetXPhoto; int m_offsetYPhoto; --- 735,740 ---- public MapWindow parentMapWindow; private boolean displayPhoto = false; + private Bitmap m_photo; int m_offsetXPhoto; int m_offsetYPhoto; Index: GMap.java =================================================================== RCS file: /cvsroot/hipgmap/gmap/com/trileet/gmap/GMap.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** GMap.java 8 Apr 2005 00:07:50 -0000 1.25 --- GMap.java 8 Apr 2005 17:35:58 -0000 1.26 *************** *** 243,247 **** public static int requestURL(String url, ResponseListener listener){ boolean kh = false; ! if (url.substring(7,9).equals("kh")) { System.out.println("Got a kh response"); kh = true; --- 243,250 ---- public static int requestURL(String url, ResponseListener listener){ boolean kh = false; ! //http://hipster.trileet.com/tmpimg/img.php?url=http%3A%2F%2Fkh ! if ((url.length()>9 && url.substring(7,9).equals("kh")) || ! (url.length()>61 && url.substring(59,61).equals("kh")) ! ) { System.out.println("Got a kh response"); kh = true; *************** *** 249,253 **** System.out.println("REQUESTING: " + url); ! HTTPConnection.get(url, null, (short) 0, ++s_transactionId, true);//!kh); s_listeners.put(new Integer(s_transactionId), new Request(url, listener)); return s_transactionId; --- 252,256 ---- System.out.println("REQUESTING: " + url); ! HTTPConnection.get(url, null, (short) 0, ++s_transactionId, !kh); s_listeners.put(new Integer(s_transactionId), new Request(url, listener)); return s_transactionId; Index: Tile.java =================================================================== RCS file: /cvsroot/hipgmap/gmap/com/trileet/gmap/Tile.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Tile.java 7 Apr 2005 02:18:16 -0000 1.5 --- Tile.java 8 Apr 2005 17:35:58 -0000 1.6 *************** *** 3,6 **** --- 3,7 ---- import danger.ui.Pen; import danger.net.HTTPTransaction; + import danger.net.URLEncoder; import danger.ui.Bitmap; *************** *** 67,71 **** } public static String makePhotoURL(String khCoords, int zoom) { ! return "http://kh.google.com/kh?v=1&t=" + khCoords.substring(0,18-zoom); } public void handleImage(String url, Bitmap image){ --- 68,73 ---- } public static String makePhotoURL(String khCoords, int zoom) { ! return "http://hipster.trileet.com/tmpimg/img.php?url=" + ! URLEncoder.encode("http://kh.google.com/kh?v=1&t=" + khCoords.substring(0,18-zoom)); } public void handleImage(String url, Bitmap image){ Index: MapWindow.java =================================================================== RCS file: /cvsroot/hipgmap/gmap/com/trileet/gmap/MapWindow.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** MapWindow.java 4 Apr 2005 03:00:19 -0000 1.14 --- MapWindow.java 8 Apr 2005 17:35:58 -0000 1.15 *************** *** 146,151 **** m_tileSet.toggleDrawPoly(); return true; ! } return super.receiveEvent(e); } --- 146,158 ---- m_tileSet.toggleDrawPoly(); return true; ! case DEBUG: ! debug(); ! return true; ! case SAVE_TILE: ! System.out.println("Drilling."); ! m_tileSet.drill(); ! return true; } + return super.receiveEvent(e); } |