Post Top Ad

July 22, 2014

Android Google Maps Chapter 2

This is the second chapter about creating a android google map with google map api v2




In the previous chapter i have explained about main layout file and the manifest file to load a map inside the emulator. Now this chapter will explain about the main activity of the map.

public class MainActivity extends FragmentActivity {
   
    private static final int GPS_ERRORDIALOG_REQUEST = 9001;
    private GoogleMap mMap;
    private static final double SEATTLE_LAT = 6.939378, // if you want to enable satellite views
            SEATTLE_LNG = 79.840336;
        //    SYDNEY_LAT =  ;
        //    SYDNEY_LNG = 151.20699,
        //    NEWYORK_LAT = 40.714353,
        //    NEWYORK_LNG = -74.005973;
    private static final float DEFAULTZOOM = 7; // to set the zoom level

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_main);
        if (servicesOK()) {
            setContentView(R.layout.activity_main);
       
            if (initMap()) {
                Toast.makeText(this, "Ready to map!", Toast.LENGTH_SHORT).show();
            //    gotoLocation(SEATTLE_LAT, SEATTLE_LNG,DEFAULTZOOM);
                mMap.setMyLocationEnabled(true); 
            }
            else {
                Toast.makeText(this, "Map not available!", Toast.LENGTH_SHORT).show();
            }
        }
        else {
            setContentView(R.layout.activity_main);
        }
             mMap=((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
//        if(mMap!=null)
//            mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
       
    }

    private void hideSoftKeyboard(View v) {
        InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
    }
   
    public void geoLocate(View v){ //Geocoder may return IOException
        hideSoftKeyboard(v);

        EditText et = (EditText) findViewById(R.id.editText1);
        String location = et.getText().toString();

        try {
            Geocoder gc = new Geocoder(this); //    when you search you will get back a java list
            List<Address> list = gc.getFromLocationName(location, 1); // Address is Android thing
            //getFromLocationName is a method of Geocoder class
            // i only want a single  item
            Address add = list.get(0); // give me the first and only item in the list
            String locality = add.getLocality();
           
            Toast.makeText(this, locality, Toast.LENGTH_LONG).show(); // To check whether Geocoder  is working or not
            //Toast.makeText(this, locality, Toast.LENGTH_LONG).show();

/*    double lat = add.getLatitude();
            double lng = add.getLongitude();

            gotoLocation(lat, lng, DEFAULTZOOM);
*/
        } catch (IOException e) {

            Log.d("EXCEPTION:", "Failed to do something: " + e.getMessage());
            Log.d("EXCEPTION: " + method,  message);
        }
    }
   
    private void gotoLocation(double lat, double lng,float zoom) {
        LatLng ll = new LatLng(lat, lng);
        CameraUpdate update = CameraUpdateFactory.newLatLngZoom(ll, zoom);
        mMap.moveCamera(update);
       
    }
   
    public boolean servicesOK() {
        int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
       
        if (isAvailable == ConnectionResult.SUCCESS) {
            return true;
        }
        else if (GooglePlayServicesUtil.isUserRecoverableError(isAvailable)) {
            Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST);
            dialog.show();
        }
        else {
            Toast.makeText(this, "Can't connect to Google Play services", Toast.LENGTH_SHORT).show();
        }
        return false;
    }
   
    private boolean initMap() {
        if (mMap == null) {
            SupportMapFragment mapFrag =
                    (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
            mMap = mapFrag.getMap();
        }
        return (mMap != null);
    }
   

    private void messageBox(String method, String message)
    {
        Log.d("EXCEPTION: " + method,  message);

        AlertDialog.Builder messageBox = new AlertDialog.Builder(this);
        messageBox.setTitle(method);
        messageBox.setMessage(message);
        messageBox.setCancelable(false);
        messageBox.setNeutralButton("OK", null);
        messageBox.show();
    }

// if you want to load different map versions according to user selection

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case R.id.mapTypeNone:
            mMap.setMapType(GoogleMap.MAP_TYPE_NONE);
            break;
        case R.id.mapTypeNormal:
            mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
            break;
        case R.id.mapTypeSatellite:
            mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
            break;
        case R.id.mapTypeHybrid:
            mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
            break;
        default:
            break;
        }
        return super.onOptionsItemSelected(item);
    }
}

Most probably when you run this code you will not see any output in the default android emulator and it will ask to update google play services. The simple answer for this problem is to try and run your map using a mobile phone. otherwise you can use install the google play services into your android emulator which shoud be done in a simple work around.
July 21, 2014

How to change the name of an iOS app?

Once, I began an iPhone project with a dummy development code name, and then I wanted to change the name of the project since its nearly finished. But I was not sure how to do this with Xcode, trying the obvious of changing the application's name in the pinfo, causes the signing process to go wrong  and my app didn't launch giving me a Launcher error.

I thought of making a  new project and copy paste everything over, but it seemed so primitive.Finally i found the solution after trying different ways.

Here are the steps to follow.
  1. Go to Targets in Xcode
  2. "Get Info" on your project's target (your current dummy development name)
  3. Search for "Product Name" under "Packaging". Change the value of that what you want the new program name is going to be.
June 20, 2014

Temporarily disable Eclipse plugin

For my friends project i wanted to restart eclipse plugin disabled so that it is possible to understand whether plugins cause the problems in the code. So i hare post that tip and hope someone would save there time finding bugs with plugins.

Some plugins allow controlling their load-on-startup behavior. These will be listed in the preferences, under General → Startup and Shutdown. If the plugin provides view, you will need to close those views (in all perspectives) for this to work.

You can simply uptick and select only the necessary plugins to be loaded.

June 16, 2014

Install Google Play on Genymotion 2.0

So the new Genymotion 2.0 no longer comes with Google API’s and for me that just a buzz kill and I admit I have enjoyed the luxuries of having the Play Store in my virtual devices. So I have a solution for you!

In Genymotion create a new device. In my test case I created a
Nexus One – 4.3 – API 18 480×800
Download  Google Apps zip file. For my virtual device I used the latest Universal package ( 20130813)
Start the virtual device and once it is up and running drag and drop the zip file onto the device.



Next you will get a file flashable dialog click ok.


You will continue to see the File Transfer dialog let it run. You will (may) get errors that pop up just ignore them for now. When you get a file flashed successful dialog, click ok.


Errors may be something related to a Google App like Search or Play. Click Ok.

Restart the virtual device. You may still be getting error dialogs like the one below. just click ok and carry on.




 If the Add Google Account Screen does not come up right away go to the apps and open up Play Store this should trigger the Add a Google Account screen.  go ahead and select the option appropriate for you and sign in or create an account. During the process you still may get errors like before just ignore it and click OK.



You will be prompted to agree with license agreement and so forth. Continue on.
Next you should see the Play Store open.
First thing I recommend doing is updating Google apps:
Menu button>My apps>update all



From this point on you should be good to go.
I went through this process a number of times and sometimes the apps did not show up in “My apps” section however if I searched for the app it would allow me to update.

If you are working with a different API this may work or you can try one of the other versions of Google Apps.   I hope this has been helpful.











June 16, 2014

How to get the real URL Target of a Short URL or Tiny URL?



Important Reasons to use a Unshort Tool

To use a Unshort Tool, UnShortener or DeShortener is always a good idea. Don't forget all the Pishing and Malware out there. The tools help you to find out the real target of any link and helps you not to end up on a Trojan site or any site which tries to install software you don't need and want.

Make a short URL long again

Find out the real URL of a Short Tiny URL

If you use Twitter, Facebook, Google or any other popular website, you find Short Url's everywhere. There are different names for this kind of links:
Short URL, Small URL, Tiny URL, but it's all the same.
If you see a link like this url.xy/123 you can't see the web site target, either you click on it, or you try to unshort such a short url. If you use a tool like real-url.org or unshort.me , it's easy and simple. The unshort tools find out the target address of a short link.

NOTE: You will only see the Final Target! What does this mean?
The used example is perfect to explain it.

(The links didn't work, this is only for example!)

(1) url.xy/123 links to ->
(2) url2.xy
this links to ->
(3) url3.xy

As you can see shows a unshort tool as target address (3), even if the first target was (2) and not (3).
Today internet marketers use tracking tools from different companies with long cryptical url's. The good news is that you can use a unshort tool also to find out the real target of such links.

During testing i noticed, that not all free URL Unshortener work correct.
Best results i got with the tools you find listed here.

Best Free Unshort URL Tools - Unshort any URL

real-url.org
unshort.me .....my recommendation
unshorten.com
May 29, 2014

Android 3rd Tutorial: Layout Options FILL_PARENT, MATCH_PARENT , WRAP_CONTENT


• FILL_PARENT (renamed MATCH_PARENT in API Level 8 and higher), which means that the View wants to be as big as its parent (minus padding)
•WRAP_CONTENT, which means that the View wants to be just big enough to enclose its content (plus padding)
Either attribute can be applied to View's (visual control) horizontal or vertical size. It's used to set a View or Layouts size based on either it's contents or the size of it's parent layout rather than explicitly specifying a dimension.

fill_parent
(deprecated and renamed MATCH_PARENT in API Level 8 and higher)
Setting the layout of a widget to fill parent will force it to expand to take up as much space as is available within the layout element it's been placed in. It's roughly equivalent of setting the dock style of a Windows Form Control to Fill.
Setting a top level layout or control to fill parent will force it to take up the whole screen.

wrap_content
Setting a View's size to wrap content will force it to expand only far enough to contain the values (or child controls) it contains. For controls -- like text boxes (TextView) or images (ImageView) -- this will wrap the text or image being shown. For layout elements it will resize the layout to fit the controls / layouts added as its children.
It's roughly the equivalent of setting a Windows Form Control's Auto size property to True.

Online Documentation
There's some details in the Android code documentation here


May 29, 2014

Styling Android: Online Tools

As mobile developers Styling Android Application is the biggest pain. But thanks to this Online tool
you can reduce your hard times.

Try it,


Android Asset Studio

Icon generators — Make icons for your app

Icon generators allow you to quickly and easily generate icons from existing source images, clipart, or text.

My Instagram