Showing posts with label BUMC Mobile. Show all posts
Showing posts with label BUMC Mobile. Show all posts

Wednesday, June 13, 2012

[Android] Google map with own logo

Show Google map with own logo where you want to mark. Just like this.



Before you start, you should make sure your project is built by google API, not Android.

package Byung_Yong.sample.mapView;

import java.util.List;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.os.Bundle;
import android.util.Log;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

public class Map extends MapActivity{

 MapView mapview;

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  
  mapview = (MapView) findViewById(R.id.mapview);
                mapview.setBuiltInZoomControls(true);
  mapview.setSatellite(false);  
  GeoPoint gpoint = new GeoPoint(12345678,12345678);   
  MapController controller = mapview.getController();  
  controller.animateTo(gpoint);
  controller.setZoom(16); 
  Bitmap image = 
                      BitmapFactory.decodeResource(getResources(), R.drawable.place);
  
  MyOverlay myoverlay = new MyOverlay(image);

  List overlayList = mapview.getOverlays();
  overlayList.add(myoverlay);
  
  }
  @Override
  protected boolean isRouteDisplayed() {
   // TODO Auto-generated method stub
   return false;
  }
 } 
 
 class MyOverlay extends Overlay {
 
  Bitmap bitmap; 
  public MyOverlay(Bitmap bitmap){
  this.bitmap = bitmap;
 }
 
 @Override
 public void draw(Canvas canvas, MapView mapView, boolean shadow) {
  super.draw(canvas, mapView, shadow);
  
  Log.d("BB", "overlay");

  Paint paint1 = new Paint(); 
  Paint paint2 = new Paint();
  paint2.setARGB(255, 0, 0, 0); 
  
  GeoPoint geopoint = new GeoPoint(12345678,12345678);
  Point geopix = new Point();
  Projection project = mapView.getProjection();

  project.toPixels(geopoint, geopix);
  canvas.drawBitmap(bitmap, geopix.x-50, geopix.y, paint1); 
  canvas.drawText("My Church", geopix.x-50, geopix.y+80, paint2);  
 }
}

You can easy to get the location information by searching at Google map.

Press right mouse where you want to mark, and click "What's here".

Then you could see the two 8 digit numbers of coordinate values on search bar or put the mouse on the arrow mark.

Copy the numbers and paste on highlight below.


Manifest will be like this.

Important!!!! Look carefully the highlight part.

You should add "com.google.android.maps" at application and make it "true" just like line 19.



Your Layout can be similar like this.

You should get Google API key by following the direction of below link.

http://mirnauman.wordpress.com/2012/01/26/how-to-get-google-maps-api-key-for-android-issues-and-errors-solved/


Sunday, June 10, 2012

[Android] webView with a table format of HTML




WebView with a table format of HTML.
package ByungYong.library.webView;

import android.app.*;
import android.os.*;
import android.view.*;
import android.webkit.*;
import android.widget.*;

public class WebViewActivity extends Activity {
 WebView mWeb;
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  mWeb = (WebView)findViewById(R.id.web);
        mWeb.loadUrl("file:///android_asset/test.html");
        mWeb.getSettings().setJavaScriptEnabled(true);
        mWeb.getSettings().setSaveFormData(true);
        mWeb.getSettings().setBuiltInZoomControls(true);
        mWeb.setWebViewClient(new MyWebClient());
 }

 
 class MyWebClient extends WebViewClient {
  public boolean shouldOverrideUrlLoading(WebView view, String url) {
   view.loadUrl(url);
   return true;
  }
 }
}
layout can be like this.

Add HTML code into assets.

Don't forget add the code below on AndroidManifest.xml