Thursday 21 January 2016

Starting with Google Maps V2 in Android

Starting with Google Maps V2 in Android Hi all, In today's tutorial lets see 1. How we can add a Google Map to our Android project using Android Studio? 2. Showing a location in the Google Map. 3. Adding Markers in Google Map. 4. Getting location on Tapping on Marker info Window in Google Maps. Before you start coding, make sure Android studio is all set up for Running the Maps application. You will need Google play Services In the app-level build.gradle add this
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}
In the Module-level build.gradle add this in the dependencies
dependencies{
 compile 'com.google.android.gms:play-services:8.4.0'
 compile 'com.android.support:support-v4:23.1.1'
}

android{
 compileSdkVersion 'Google Inc.:Google APIs:23'    
 buildToolsVersion '23.0.2'
}
These are the main things you may have your own settings in the build.gradle. How we can add a Google Map to our Android project using Android Studio? Take a look at the screenshot for adding new project to your Android Studio and click finish. [Image 1] Now Google will create everything you need for a MapActivity except the Google Maps Key. You need to get the Google maps key before proceeding. For that you need to sign in to Google and navigate to https://developers.google.com/maps/documentation/android-api/. Follow the instructions and get the key. A sample key would look like this. "AIzaSyC1mQQLwwcms-bAaNmhKUNiW_HBjftQiSE" Once you get the key, you can start coding. Now we will check our layout. In the layout I am adding once edittext to search for a location in maps. The final layout would look like this. [xml] [/xml] Here is our Activity... This is the complete activity where we will add a marker on searched location. Then we will add a tap listener on the info window in the marker to get the location. [java] package com.catalinamarketing.activities; import android.content.Context; import android.location.Address; import android.location.Geocoder; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.util.Log; import android.view.KeyEvent; import android.view.inputmethod.EditorInfo; import android.widget.EditText; import android.widget.TextView; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.OnMapReadyCallback; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.model.CameraPosition; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.Marker; import com.google.android.gms.maps.model.MarkerOptions; import com.google.android.maps.GeoPoint; import com.modivmedia.mcscan.R; import java.util.List; public class MapActivity extends FragmentActivity implements OnMapReadyCallback, GoogleMap.OnMarkerClickListener { private GoogleMap mMap; public static final String TAG = "MAP"; EditText searchLocationTv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_map); searchLocationTv = (EditText) findViewById(R.id.searchTxt); // Obtain the SupportMapFragment and get notified when the map is ready to be used. SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); // Acquire a reference to the system Location Manager LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { // Called when a new location is found by the network location provider. setLocationInMap(location); } public void onStatusChanged(String provider, int status, Bundle extras) { } public void onProviderEnabled(String provider) { } public void onProviderDisabled(String provider) { } }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); searchLocationTv.setOnEditorActionListener(new TextView.OnEditorActionListener() { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) { Log.i(TAG, "Enter pressed"); GeoPoint g = getLocationFromAddress(searchLocationTv.getText().toString().trim()); double latitude = g.getLatitudeE6() / 1E6; double longitude = g.getLongitudeE6() / 1E6; Location location = new Location(searchLocationTv.getText().toString().trim()); location.setLatitude(latitude); location.setLongitude(longitude); setLocationInMap(location); } return false; } }); } /** * Manipulates the map once available. * This callback is triggered when the map is ready to be used. * This is where we can add markers or lines, add listeners or move the camera. In this case, * we just add a marker near Sydney, Australia. * If Google Play services is not installed on the device, the user will be prompted to install * it inside the SupportMapFragment. This method will only be triggered once the user has * installed Google Play services and returned to the app. */ @Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap; mMap.setOnMarkerClickListener(this); Log.i(TAG, "Map is ready..."); mMap.setOnInfoWindowClickListener( new GoogleMap.OnInfoWindowClickListener() { @Override public void onInfoWindowClick(Marker arg0) { // TODO Auto-generated method stub arg0.hideInfoWindow(); double dlat = arg0.getPosition().latitude; double dlon = arg0.getPosition().longitude; String slat = String.valueOf(dlat); String slon = String.valueOf(dlon); Log.i(TAG, "LAt " + dlat + "Long = " + dlon); } } ); } private void setLocationInMap(Location location) { Log.i(TAG, "Setting Location in Map..."); LatLng myLocation = new LatLng(location.getLatitude(), location.getLongitude()); mMap.addMarker(new MarkerOptions().position(myLocation).title(searchLocationTv.getText().toString().trim())).showInfoWindow(); CameraPosition cameraPosition = new CameraPosition.Builder().target(myLocation).zoom(2).build(); mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); } //Find 5 names and return the first one for the name provided.. private GeoPoint getLocationFromAddress(String strAddress) { Geocoder coder = new Geocoder(this); List
address; GeoPoint p1 = null; try { address = coder.getFromLocationName(strAddress, 5); if (address == null) { return null; } Address location = address.get(0); location.getLatitude(); location.getLongitude(); p1 = new GeoPoint((int) (location.getLatitude() * 1E6), (int) (location.getLongitude() * 1E6)); } catch (Exception e) { } return p1; } @Override public boolean onMarkerClick(final Marker marker) { Log.i(TAG, "marker clicked"); marker.showInfoWindow(); return true; } } [/java] Here is how the AndroidManifest.xml will look like.. Make sure you add the permissions for location and internet here.. Also add the Android Maps API key. [xml] [/xml] You are now ready to run the application.

Monday 27 May 2013

How to read a folder structure in the assets folder in Android?

    AssetManager mngr_spinner = getAssets();
 try {
           int img_count = 0;
           folder_array = mngr_spinner.list(parent_folder_name);
    labels_array = new String[folder_array.length];
           for (int i = 0; i < folder_array.length; i++) 
        {
    // System.out.println("Folder " + folder_array[i]);
    if ((folder_array[i].endsWith(".png") || folder_array[i].endsWith(".jpg"))) 
         {
           img_count++;
         }
        }
      } catch (IOException e1) 
                  {
     e1.printStackTrace();
    }
Note : The folder will not be read if it has no contents in it.

Sunday 26 May 2013

Samsung Galaxy S4


Samsung Galaxy S4

Samsung Galaxy S4

Display
5inch Full HD Super AMOLED (1920 x 1080) display, 441 ppi


AP
1.9 GHz Quad-Core Processor / 1.6 GHz Octa-Core Processor
The seletion of AP will be differed by markets
Network
2.5G (GSM/ GPRS/ EDGE): 850 / 900 / 1800 / 1900 MHz
3G (HSPA+ 42Mbps): 850 / 900 / 1900 / 2100 MHz
4G (LTE Cat 3 100/50Mbps) : up to 6 different band sets (Dependent on market)
OS
Android 4.2.2 (Jelly bean)

Memory
16 / 32 / 64GB memory + microSD slot (up to 64GB), 2GB RAM
Camera
Main(Rear): 13 Mega pixel Auto Focus camera with Flash & Zero Shutter Lag, BIS
Sub (Front): 2 Mega pixel camera, Full HD recording @30fps with Zero Shutter Lag, BIS

Camera Features
Dual Shot , Drama Shot, Sound & Shot, 360 Photo, Animated Photo, Eraser, Night, Best Photo, Best Face, Beauty Face, HDR (High Dynamic Range), Panorama, Sports


Video
Codec: MPEG4, H.264, H.263, DivX, DivX3.11, VC-1, VP8, WMV7/8, Sorenson Spark, HEVC
Recording & Playback: Full HD (1080p)
Audio
Codec: MP3, AMR-NB/WB, AAC/AAC+/eAAC+, WMA, OGG,
FLAC, AC-3, apt-X
Additional Features
Group Play: Share Music, Share Picture, Share Document,
Play Games
Story Album, S Translator, Optical Reader
Samsung Smart Scroll, Samsung Smart Pause, Air Gesture,
Air View
Samsung Hub, ChatON (Voice/Video Call, Share screen,
3-way calling) Samsung WatchON
S Travel (Trip Advisor), S Voice™ Drive, S Health
Samsung Adapt Display, Samsung Adapt Sound, Auto adjust touch sensitivity (Glove friendly)
Safety Assistance, Samsung Link, Screen Mirroring
Samsung KNOX (B2B only)
Google Mobile Services
Google Search, Google Maps, Gmail, Google Latitude Google Play Store, Google Plus, YouTube, Google Talk, Google Places, Google Navigation, Google Downloads, Voice Search
Sensor
Accelerometer, RGB light, Geomagnetic, Proximity, Gyro,
Barometer
Temperature & Humidity, Gesture
Dimension
136.6 x 69.8 x 7.9 mm, 130g

Connectivity
WiFi 802.11 a/b/g/n/ac (HT80)
GPS / GLONASS
NFC, Bluetooth® 4.0 (LE)
IR LED (Remote Control), MHL 2.0
Battery
2,600mAh

Sunday 17 March 2013

Facebook CEO - Mark Zuckerberg on top CEO List




The Facebook chief earned a 99 percent approval rating from his social network employees, topping Glassdoor's annual list of the 50 highest rated CEOs.
Glassdoor surveyed hundreds of thousands of employees across various industries, and based on their feedback over the past 12 months, ranked the most impressive bosses, one of which happens to be hoodie-wearing billionaire Zuck.

Read the complete story here

Saturday 16 March 2013

Samsung to Launch First Tizen-Powered Phone


In an interview with The Wall Street Journal, Samsung mobile chief J.K. Shin said Samsung plans to release a Tizen-powered phone in the third quarter, raising questions about whether it is planning to move away from Google’s Android in the future.

Read more from here
http://blogs.wsj.com/digits/2013/03/14/samsung-to-launch-first-tizen-powered-phone-in-3q/

Saturday 29 December 2012

How to load a spinner with values from SQlite Database in android?


Here is a simple example showing how to load a database values in a spinner in android.



OK we will start.
This is the layout for the spinner row.
spinner_row.xml




activity_main.xml












Read the complete post here...

http://www.coderzheaven.com/2012/11/18/load-spinner-values-sqlite-database-android/

How to crop an Image in Android?


This is a sample program that launches the camera and crop the captured image.

Check this link to another crop image example.









This is the layout xml.
<strong>activity_main.xml</strong>

[xml]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="3dp"
        android:text="@string/intro"
        android:textStyle="bold" />

    <Button
        android:id="@+id/capture_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/capture" />

    <ImageView
        android:id="@+id/picture"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:contentDescription="@string/picture" />

</LinearLayout>
[/xml]

Now this is the Main Java File that implements the crop functionality.

Read More from here...

http://www.coderzheaven.com/2012/12/15/crop-image-android/

Monday 24 December 2012

Select an Image from gallery in ANDROID and show it in an ImageView.

Hi all
In this tutorial I will show you how to get an image from your phone gallery and show it in an imageview.
Here we use intents to open up the image gallery and get the image URI.
Here I am setting the image type as “image” to get only the images.
And on onActivityResult if the result is OK, then get the data using getData() function and converting the imageURI to the stringPath.

Read more from here
http://www.coderzheaven.com/2012/04/20/select-an-image-from-gallery-in-android-and-show-it-in-an-imageview/



Saturday 15 December 2012

Customizing a spinner in android.

Hello everyone.........

 You all knew that a spinner or combobox is an inbuilt widget in android. And Like any other widgets spinners are also customizable. Here is a simple example to customize a spinner. First we will look at the java code. The getView method is called for each row in the spinner. So with the help of an Layout Inflater you can inflate any layout for each row. At extreme you can have each layout for each row. Check these older posts about spinner.

 1. How to get a selected Item from a spinner in ANDROID?
 2. How to set an item selected in Spinner in ANDROID?
 3. How to create a custom ListView in android?

Check out these of ListViews

 1. Simplest Lazy Loading ListView Example in Android with data populated from a MySQL database using php.
 2. How to add checkboxes and radio buttons to ListView in android? OR How to set single choice items in a ListView in android?

 Read complete code from here http://www.coderzheaven.com/2011/07/18/customizing-a-spinner-in-android/

Monday 5 November 2012

ActionBar with Search Option and other options in Android.


This is the example showing how to start with ActionBar in android.

1. <a href="http://www.coderzheaven.com/2012/01/28/android-removes-the-need-of-menu-button-from-devices-with-actionbar/" title="ActionBar" target="_blank">Android removes the need of Menu button from devices with ActionBar.</a>

2. <a href="http://www.coderzheaven.com/2012/08/23/start-actionbar-android/" title="ActionBar" target="_blank">How to start with ActionBar in Android?</a>

3. <a href="http://www.coderzheaven.com/2012/09/28/dynamically-adding-removing-toggling-removing-actionbar-tabs-android-part-2/" title="ActionBar" target="_blank">Dynamically Adding, Removing, Toggling and Removing all ActionBar Tabs in Android – Part 2?</a>
 

Read complete post from here..

http://www.coderzheaven.com/2012/10/20/actionbar-search-option-options-android/