Thursday, 2 June 2016

Get Location by lat,Long Android


public String GetAddress(double latitude, double longitude) {

    Geocoder geocoder = new Geocoder(this, Locale.getDefault());
    String city = "", state = "", address = "";
    try {
        List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
        address = addresses.get(0).getAddressLine(0) + " " +
      addresses.get(0).getAddressLine(1);
        city = addresses.get(0).getLocality();
        state = addresses.get(0).getAdminArea();
        String zip = addresses.get(0).getPostalCode();
        String country = addresses.get(0).getCountryName();
    } catch (Exception e) {

    }
    return city;
}

Wednesday, 1 June 2016

Making DrawableLeft,Right,Down,Top Clickable Android



edtPassword.setOnTouchListener(new View.OnTouchListener() {
    @Override    public boolean onTouch(View v, MotionEvent event) {
        final int DRAWABLE_LEFT = 0;
        final int DRAWABLE_TOP = 1;
        final int DRAWABLE_RIGHT = 2;
        final int DRAWABLE_BOTTOM = 3;

        if (event.getAction() == MotionEvent.ACTION_UP) {
            if (event.getRawX() >= (edtPassword.getRight() - 
   edtPassword.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {

                if (edtPassword.getInputType() == (InputType.TYPE_CLASS_TEXT |
                        InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD)) {

                    edtPassword.setInputType(InputType.TYPE_CLASS_TEXT |
                            InputType.TYPE_TEXT_VARIATION_PASSWORD);
                } else {
                    edtPassword.setInputType(InputType.TYPE_CLASS_TEXT |
                            InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
                }

                return false;
            }
        }
        return false;
    }
});

Password Visible and Invisible By Drawable Right Android


Step 1:

You have to add android:drawableRight="@drawable/show_password" in 
EditText


Step 2:


edtPassword.setOnTouchListener(new View.OnTouchListener() {
    @Override    public boolean onTouch(View v, MotionEvent event) {
        final int DRAWABLE_LEFT = 0;
        final int DRAWABLE_TOP = 1;
        final int DRAWABLE_RIGHT = 2;
        final int DRAWABLE_BOTTOM = 3;

        if (event.getAction() == MotionEvent.ACTION_UP) {
            if (event.getRawX() >= (edtPassword.getRight() - 
edtPassword.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds()
.width())) {

                if (edtPassword.getInputType() == (InputType.TYPE_CLASS_TEXT |
                        InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD)) {

                    edtPassword.setInputType(InputType.TYPE_CLASS_TEXT |
                            InputType.TYPE_TEXT_VARIATION_PASSWORD);
                } else {
                    edtPassword.setInputType(InputType.TYPE_CLASS_TEXT |
                            InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
                }

                return false;
            }
        }
        return false;
    }
});


you can use given svg (copy and save it as show_password.xml)

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="15dp"
        android:height="15dp"
        android:viewportWidth="36.0"
        android:viewportHeight="36.0">
    <path
        android:pathData="M18,6C8.06,6 0,18 0,18s8.06,12 18,12c9.94,0 18,
-12 18,-12S27.94,6 18,6zM18.02,25.98c-4.42,0 -8,-3.58 -8,-7.98c0,-4.41 3.58,
-7.98 8,-7.98s8,3.57 8,7.98C26.02,22.41 22.44,25.98 18.02,25.98zM18,15.01c-1.65,
0 -2.98,1.34 -2.98,3s1.34,3 2.98,3c1.65,0 2.98,-1.34 2.98,-3S19.65,15.01 18,15.01z"

        android:fillColor="#A1A1A1"/>
</vector>

PlacePicke Example Android


Step 1:

add in android app gradle:

compile 'com.google.android.gms:play-services-nearby:8.4.0'compile 'com.google.android.gms:play-services-location:8.4.0'

First of all need to API key and Enable Google Place API to search and get place details. Add your API key to your app manifest ,need to replacing YOUR_API_KEY with your own API key:
<application>
  ...
  <meta-data
      android:name="com.google.android.geo.API_KEY"
      android:value="YOUR_API_KEY"/>
</application>
Step 2:
int PLACE_PICKER_REQUEST = 1;
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();

startActivityForResult(builder.build(this), PLACE_PICKER_REQUEST);

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  if (requestCode == PLACE_PICKER_REQUEST) {
    if (
resultCode == RESULT_OK) {
        Place place = PlacePicker.getPlace(data, this);
        String toastMsg = String.format("Place: %s", place.getName());
        Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show();
    }
  }
}
you can see given link for customize ui:
https://developers.google.com/places/android-api/placepicker#add