4 Replies - 1077 Views - Last Post: 18 January 2012 - 10:59 PM

#1 spadercool  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-January 12

Java Android questions

Posted 11 January 2012 - 09:08 PM

package net.learn2develop.LBS;

import net.learn2develop.LBS.R;
import android.app.*;
import android.content.Context;
import android.content.res.Resources;
import android.os.*;
import android.view.*;
import android.view.MenuItem;
import android.widget.*;
import com.google.android.maps.*;
import android.graphics.*;
import java.util.*;
import android.location.*;
import java.io.*;


public class ShowMap extends Fragment{
	private MapView mapView;
	private MapController mc;
	private GeoPoint p;
	
	class mapOverlay extends com.google.android.maps.Overlay{
		@Override
		public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when){
			super.draw(canvas, mapView, shadow);
			Point screenPts = new Point();
			mapView.getProjection().toPixels(p, screenPts);
			Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.pushpin);
			canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);
			return true;
		}
	@Override
	public boolean onTouchEvent(MotionEvent event, MapView mapView){
		if (event.getAction()== 1){
			GeoPoint p = mapView.getProjection().fromPixels((int) event.getX(), (int) event.getY());
			Geocoder geoCoder = new Geocoder(getActivity(), Locale.getDefault());
			try {
				List<Address> addresses =geoCoder.getFromLocation(p.getLatitudeE6()/1E60, p.getLongitudeE6()/1E6, 1);
				String add = "";
			if (addresses.size()>0){
				for (int i=0;
				i<addresses.get(0).getMaxAddressLineIndex();
				i++)
					add+= addresses.get(0).getAddressLine(i)+"\n";
				}
			Toast.makeText(getActivity(), add, Toast.LENGTH_SHORT).show();
			}
			catch (IOException e){
				e.printStackTrace();
			}
			return true;
		}
		return false;
	}
	}
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
		return inflater.inflate(R.layout.showmap, container,false);
	}
	public Context getActivity() {
		// TODO Auto-generated method stub
		return null;
	}
	public Resources getResources() {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
public void onstart(){
		super.onstart();
		mapView =(MapView) getActivity().findViewById(R.id.mapView);
		mc =mapView.getController();
		mapView.setBuiltInZoomControls(true);

	}
	public void gotoLocation(String latlng){
		String [] coordinates =latlng.split(",");
		double lat =Double.parseDouble(coordinates[0]);
		double lng= Double.parseDouble(coordinates[1]);
		p = new GeoPoint((int) (lat*1E6), (int) (lng*1E6));
		mc.animateTo(p);
		mc.setZoom(16);
		
		mapOverlay mapOverlay = new mapOverlay();
		List<Overlay> listOfOverlays = mapView.getOverlays();
		listOfOverlays.clear();
		listOfOverlays.add(mapOverlay);
		
		mapView.invalidate();
		
		
	}
	 @Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setHasOptionsMenu(true);
		
	}
	private void setHasOptionsMenu(boolean B)/> {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void onCreateOptionsMenu(Menu menu, MenuInflater inflater){
		super.onCreateoptionsMenu(menu, inflater);
		CreateMenu(menu);
	}
	@Override
	public boolean onOptionsItemsSelected(MenuItem item){
		return MenuChoice(item);
	}
	private void CreateMenu(Menu menu){
		MenuItem mnu1 = menu.add(0,0,0, "Start Tracking");
		{
			mnu1.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM |
					MenuItem.SHOW_AS_ACTION_WITH_TEXT);
					
		}
		MenuItem mnu2 = menu.add(0,1,1, "Stop Tracking");
		{
			mnu2.setShowAsAction(
					MenuItem.SHOW_AS_ACTION_IF_ROOM | 
					MenuItem.SHOW_AS_ACTION_WITH_TEXT);
					
		}
		MenuItem mnu3 = menu.add(0,2,1, "Use GPS");
		{
			mnu3.setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT);
			mnu3.setCheckable(true);
		}
		MenuItem mnu4 = menu.add(0,3,1, "Use Cellular/Wifi");
		{
			mnu4.setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT);
			mnu4.setCheckable(true);
		}
	}
    private boolean MenuChoice(MenuItem item)
    {   
    	MainActivity mainActivity;
    	mainActivity = (MainActivity) getActivity();
    	
        switch (item.getItemId()) {
        case 0:        	
            Toast.makeText(getActivity(), "Tracking turned on", 
                Toast.LENGTH_LONG).show();            
            mainActivity.TrackingUsingGPS(true);
            mainActivity.TrackingUsingCellularWiFi(true);            
            return true;
        case 1:
            Toast.makeText(getActivity(), "Tracking turned off", 
                Toast.LENGTH_LONG).show();
            mainActivity.TrackingUsingGPS(false);
            mainActivity.TrackingUsingCellularWiFi(false);
            return true;
        case 2:
        	if (!item.isChecked()) {
                Toast.makeText(getActivity(), 
                	"Using GPS for location tracking", 
                    Toast.LENGTH_LONG).show();
            }        	
            item.setChecked(!(item.isChecked()));
            mainActivity.TrackingUsingGPS(item.isChecked());
            return true;
        case 3:
        	if (!item.isChecked()) {
                Toast.makeText(getActivity(), 
                	"Using Cellular/WiFi for location tracking", 
                    Toast.LENGTH_LONG).show();
        	}
            item.setChecked(!(item.isChecked()));
            mainActivity.TrackingUsingCellularWiFi(item.isChecked());
            return true;
        }
        return false;
    }
}
	


I am getting errors on all the MenuItem.SHOW_AS_ACTION_WITH_TEXT and MenuItem.SHOW_AS_ACTION_IF_ROOM items. Can anyone help me?? This is for geocoding

Is This A Good Question/Topic? 0
  • +

Replies To: Java Android questions

#2 smohd  Icon User is offline

  • Critical Section
  • member icon



Reputation: 1745
  • View blog
  • Posts: 4,409
  • Joined: 14-March 10

Re: Java Android questions

Posted 11 January 2012 - 09:11 PM

*Moved to Android Mobile development forum where you can get better reply.
We have a forum for mobile development and subform for android, so use it with android questions and let java forums be for java related questions
Was This Post Helpful? 0
  • +
  • -

#3 H3R3T1C  Icon User is offline

  • Android Expert
  • member icon

Reputation: 275
  • View blog
  • Posts: 757
  • Joined: 30-March 07

Re: Java Android questions

Posted 11 January 2012 - 09:46 PM

What exactly does the error say?
Was This Post Helpful? 0
  • +
  • -

#4 spadercool  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-January 12

Re: Java Android questions

Posted 18 January 2012 - 01:54 PM

The error simply says that the type cannot be resolved.
Was This Post Helpful? 0
  • +
  • -

#5 cmh0114  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 143
  • Joined: 03-January 10

Re: Java Android questions

Posted 18 January 2012 - 10:59 PM

If you're using Eclipse, press Ctrl-O to automatically import the needed libraries for your code. If not, I'd double-check to make sure you've spelled everything correctly and referenced the correct libraries - some Android objects have a Java class and an Android class, and you have to make sure you choose the right one (usually Android).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1