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

Tuesday, 31 May 2016

PlaceAutocompleteIntent and PlaceAutocompleteFragment 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:

PlaceAutocompleteIntent Example


private final static int PLACE_AUTOCOMPLETE_REQUEST_CODE = 12;
LatLng latlong;

call this mehod where you want to get auto complete location:
callPlaceAutocompleteActivityIntent();



 private void callPlaceAutocompleteActivityIntent() {
        try {
            Intent intent =
      new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN)
                            .build(this);
            startActivityForResult(intent, PLACE_AUTOCOMPLETE_REQUEST_CODE);
//PLACE_AUTOCOMPLETE_REQUEST_CODE is integer for request code       
 } catch (GooglePlayServicesRepairableException | 
                   GooglePlayServicesNotAvailableException e) {
            // TODO: Handle the error.        }

    }


protected void onActivityResult(int requestCode, int resultCode, Intent data) {
 if (requestCode == PLACE_AUTOCOMPLETE_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            Place place = PlaceAutocomplete.getPlace(this, data);
            latlong = place.getLatLng();
            txtlocation.setText(place.getAddress().toString());
        } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
            Status status = PlaceAutocomplete.getStatus(this, data);
        } else if (requestCode == RESULT_CANCELED) {

        }
    }
}





PlaceAutocompleteFragment Example


<fragment
  android:id="@+id/place_autocomplete_fragment"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
  />


Java:
PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
            getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);


AutocompleteFilter typeFilter = new AutocompleteFilter.Builder()
        .setTypeFilter(AutocompleteFilter.TYPE_FILTER_ADDRESS)
        .build();
autocompleteFragment.setFilter(typeFilter);

autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
    @Override
    public void onPlaceSelected(Place place) {
        // TODO: Get info about the selected place.
        Log.i(TAG, "Place: " + place.getName());//get place details here
    }

    @Override
    public void onError(Status status) {
        // TODO: Handle the error.
        Log.i(TAG, "An error occurred: " + status);
    }
});

Customize Date



todayMonth = (TextView) findViewById(R.id.todayMonth);
todayDay = (TextView) findViewById(R.id.todayDay);
today = (TextView) findViewById(R.id.today);

tommorowyMonth = (TextView) findViewById(R.id.tommorowyMonth);
tommorow = (TextView) findViewById(R.id.tommorow);
tomorrowTxt = (TextView) findViewById(R.id.tomorrowTxt);

lastMonth = (TextView) findViewById(R.id.lastMonth);
lastDay = (TextView) findViewById(R.id.lastDay);
last = (TextView) findViewById(R.id.last);

Date d = new Date();
getdate(d, 1);




public void getdate(Date d, int id) {
    DateFormatSymbols dfs = new DateFormatSymbols();
    String[] months = dfs.getMonths();
    SimpleDateFormat mdformat = new SimpleDateFormat("dd / MM / yyyy ");
    String strDate = mdformat.format(d);


    String dateStr[] = getdateVal(strDate);
  

    if (id == 1) {
        todayMonth.setText(months[d.getMonth()]);
        todayDay.setText(dateStr[0]);

        Calendar calendar = Calendar.getInstance();

        int thisYear = calendar.get(Calendar.YEAR);
        int thisMonth = calendar.get(Calendar.MONTH);
        int thisDay = calendar.get(Calendar.DAY_OF_MONTH);
        Date dd = new Date(thisYear, thisMonth, thisDay + 1);
        date[0]=thisYear+"-"+thisMonth+"-"+thisDay;
        getdate(dd, 2);

    } else if (id == 2) {

        tommorowyMonth.setText(months[d.getMonth()]);
        tommorow.setText(dateStr[0]);
        tomorrowTxt = (TextView) findViewById(R.id.tomorrowTxt);
        tomorrowTxt.setText("TOMORROW");

        Calendar calendar = Calendar.getInstance();

        int thisYear = calendar.get(Calendar.YEAR);
        int thisMonth = calendar.get(Calendar.MONTH);
        int thisDay = calendar.get(Calendar.DAY_OF_MONTH);
        Date dd = new Date(thisYear, thisMonth, thisDay + 2);
        date[1]=thisYear+"-"+thisMonth+"-"+thisDay;
        getdate(dd, 3);


    } else if (id == 3) {

        lastMonth.setText(months[d.getMonth()]);
        lastDay.setText(dateStr[0]);

        Calendar calendar = Calendar.getInstance();

        int thisYear = calendar.get(Calendar.YEAR);
        int thisMonth = calendar.get(Calendar.MONTH);
        int thisDay = calendar.get(Calendar.DAY_OF_MONTH);
        Date dd = new Date(thisYear, thisMonth, thisDay + 1);
        String dayOfTheWeek = (String) DateFormat.format("EEEE", dd);
        date[1]=thisYear+"-"+thisMonth+"-"+thisDay;
        last.setText(dayOfTheWeek);
    }
}

public String[] getdateVal(String date) {
    String str[] = date.split("/");
    return str;

}

Monday, 30 May 2016

LinkedIn Iimplementation and Getting User Details with Android


Step 1: add dependencies in app gradle

compile project(':linkedin-sdk')


Step 2: 


public static final int LINKEDIN_SELECT = 1;
int mScialCode=1;

public void login_linkedin() {
    LISessionManager.getInstance(getApplicationContext()).init
       (this, buildScope(), new AuthListener() {
        @Override        public void onAuthSuccess() {
            getLinkedInProfileData();
            
        }

        @Override        public void onAuthError(LIAuthError error) {

           
        }
    }, true);
}


private void getLinkedInProfileData() {
    progress.show();
    String url = 
"https://api.linkedin.com/v1/people/~:(id,first-name,last-name,picture-url,email-address)";

    APIHelper apiHelper = APIHelper.getInstance(getApplicationContext());
    apiHelper.getRequest(this, url, new ApiListener() {
        @Override        public void onApiSuccess(ApiResponse apiResponse) {
            // Success!            String rr = "";
            JSONObject res = apiResponse.getResponseDataAsJson();
            Log.d("profile info", apiResponse.getResponseDataAsString());
            try {
                rr = res.getString("emailAddress");
                res.getString("lastName");
                email_id = res.getString("emailAddress");
                f_name = res.getString("firstName");
                l_name = res.getString("lastName");
                String id = res.getString("id");
                personPhotoUrl = res.getString("pictureUrl");
                sph.setString("PROFILEPIC", personPhotoUrl);
                sph.setBoolean("ISSOCIAL", true);
                isSocial = true;
                socialMeadiaType = 3;
                SinUpClient(f_name, l_name, "", email_id, "", "", "");

            } catch (JSONException e) {
       
                progress.dismiss();
            }
            progress.dismiss();
        }

        @Override        public void onApiError(LIApiError liApiError) {
            // Error making GET request!            progress.dismiss();
        }

    });
}


private static Scope buildScope() {
    return Scope.build(Scope.R_BASICPROFILE, Scope.W_SHARE, Scope.R_EMAILADDRESS);
}


@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
 
     if (mScialCode == LINKEDIN_SELECT)
        LISessionManager.getInstance(getApplicationContext())
       .onActivityResult(this, requestCode, resultCode, data);
    else {
    }
}